Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Measuring execution times

Stuart_M_
Principiante
1.322 Vistas
Is there really no built in VS tool to measure execution times?

I know of VTune but that's a little excessive for just wanting to know what my execution time is. Is there a way to obtain execution within VS2008?

Thanks
0 kudos
5 Respuestas
Paul_Curtis
Colaborador Valioso I
1.322 Vistas

The opsys can provide a timestamp when requested, so you can bracket your execution code with calls and compute the elapsed time (and, btw, WORD denotes a 2-byte integer):
[cpp]!TYPE T_SYSTEMTIME
!SEQUENCE
! integer(WORD) wYear ! knowns WORD
! integer(WORD) wMonth ! knowns WORD
! integer(WORD) wDayOfWeek ! knowns WORD
! integer(WORD) wDay ! knowns WORD
! integer(WORD) wHour ! knowns WORD
! integer(WORD) wMinute ! knowns WORD
! integer(WORD) wSecond ! knowns WORD
! integer(WORD) wMilliseconds ! knowns WORD
!END TYPE

TYPE(T_SYSTEMTIME) :: st

CALL GetLocalTime (st)
[/cpp]

Steven_L_Intel1
Empleados
1.322 Vistas
I don't know of a built-in way in VS to do this, but standard Fortran has intrinsics such as CPU_TIME and SYSTEM_CLOCK that work for timing.
jimdempseyatthecove
Colaborador Distinguido III
1.322 Vistas

Use QueryPerformanceCounter and QueryPerformanceFrequency

You may find it easier if you place these into your own functions.

The IVF team chose to use T_LARGE_INTEGER instead of T_LARGE_INTEGER_R, the "_R" has the union with an integer(8) :: QuadPart.

function GetTickNow()
use kernel32
typeT_li_li_r
sequence
union
map
T_LARGE_INTEGER :: li
end map
map
T_LARGE_INTEGER_R :: li_r
end map
end union
end type hack
integer(8) :: GetTickNow
type(T_li_li_r) :: hack
QueryPerformanceCounter(hack%li)
GetTickNow = hack%li_r
end function GetTickNow

function GetTicksPerSecond()
use kernel32
typeT_li_li_r
sequence
union
map
T_LARGE_INTEGER :: li
end map
map
T_LARGE_INTEGER_R :: li_r
end map
end union
end type hack
integer(8) ::GetTicksPerSecond
type(T_li_li_r) :: hack
QueryPerformanceFrequency(hack%li)
GetTicksPerSecond = hack%li_r
end function GetTickNow

function GetElapseTime(Tick1, Tick2)
integer(8) :: Tick1, Tick2
REAL(8) :: GetElapseTime
GetElapseTime = DBLE(Tick2-Tick1) / DBLE(GetTicksPerSecond())
end function GetElapseTime

program yourProg
integer(8) :: Tick1, Tick2
real(8) :: Time_Sub1
...
Tick1 = GetTickNow()
call Sub1
Tick2 = GetTickNow()
Time_Sub1 = GetElapseTime(Tick1, Tick2)
...

You can clean-up the code and place into module

Jim Dempsey


Stuart_M_
Principiante
1.322 Vistas
Thanks! I think CPU_time should be the simplest solution for my needs.
rogcar
Principiante
1.322 Vistas
Quoting - stubaan
Thanks! I think CPU_time should be the simplest solution for my needs.

There is an easier way, using the SECNDS function, like this:

! ----------------------------------
! Time variables
real TpInit, TpVar

! Register the beginning
TpInit = SECNDS(0.0)

! Do whatever you need
...

! Register how long your processes had taken
TpVar= SECNDS(TpInit)
! ----------------------------------

But, if you are really looking to profile your application, you should usea resource like VTune.

Regards,
Roger
Responder