Measuring execution times

Measuring execution times

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

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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):

!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)

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.

Steve - Intel Developer Support

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

www.quickthreadprogramming.com

Thanks! I think CPU_time should be the simplest solution for my needs.

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today