It is currently Thu Oct 22, 2020 9:52 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: QueryPerformanceFrequency - Procedure
PostPosted: Sat May 18, 2019 4:34 pm 
Offline
User
User

Joined: Mon Jan 21, 2019 1:41 pm
Posts: 41
Hi,

I've got this from the forum somewhere:

Code:
    Global QueryPerformanceFrequency.q : QueryPerformanceFrequency_(@QueryPerformanceFrequency)

    ; Returns the elapsed time between this call and the last call
    Procedure.d GetExecutionTime(unit.d=#Time_Millisecond)
      Protected counter.q, time.d
      Static QueryPerformanceCounter.q

      QueryPerformanceCounter_(@Counter)
      time = unit * (counter-QueryPerformanceCounter) / QueryPerformanceFrequency
      QueryPerformanceCounter = counter

      ProcedureReturn time
    EndProcedure


I can call it e.g. with:
Code:
GetExecutionTime()
; Do something here...
Debug "Time to do something: " + GetExecutionTime() + " ms"


Is there a way to expand the procedure that I could measure overlapping times?

Like this:
Code:
timeOuter.d = GetExecutionTime()
For i = 1 To 1000
  ; Do something
  timeInner.d = GetExecutionTime()
  For j = 1 To 1000
  ; Do something
  Next j
  Debug "Time for inner loop: " + GetExecutionTime(timeInner) + " ms"
Next i
Debug "Time for outer loop: " + GetExecutionTime(timeOuter) + " ms"


Top
 Profile  
Reply with quote  
 Post subject: Re: QueryPerformanceFrequency - Procedure
PostPosted: Sat May 18, 2019 4:48 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 427
Location: Germany
Have a look at this code:
Poor (wo)man's time profiling

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: QueryPerformanceFrequency - Procedure
PostPosted: Sat May 18, 2019 5:17 pm 
Offline
User
User

Joined: Mon Jan 21, 2019 1:41 pm
Posts: 41
Thanks, but all of them aren't using QueryPerformanceCounter and I don't know if it's necessary to do it with 10 times the code of this little procedure...


Top
 Profile  
Reply with quote  
 Post subject: Re: QueryPerformanceFrequency - Procedure
PostPosted: Sat May 18, 2019 5:43 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3753
Location: Utah, USA
Just a note, PB's ElapsedMilliseconds() uses QueryPerformanceTimer if it is available so if you don't need dinner resolution than a millisecond it should work as well for you.

_________________
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Jeff8888 and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye