PDA

View Full Version : cTimer handy for TBGL profiling



Petr Schreiber
29-06-2011, 20:45
Did you downloaded the ThinBASIC 1.8.8.0? Yes? Then you can take advantage of new cTimer class.
It is great little helper for performing precise time measurements, and it has one unique ability - it remembers its history.

The cTimer sample in SampleScripts does not demonstrate this feature, but it is very useful one. It is represented by two methods:

Intermediate_Count - returning total count of measurements
Intermediate_Get - to retrieve nth measurement in microseconds

With such a arsenal, you can perform the timing just by calling Elapsed method each frame and then retrieve the results later.
The following is the part of code which serves for retrieving measurement "history". The full, executable code is attached below.


Local sOut As String, i As Long, timeDelta As Double, frameRate As String

' -- Now we can trace back all the measured values using Intemediate_* methods
sOut = "Frame" + $TAB + "ms" + $TAB + "FPS" + $CRLF
For i = 1 To myTimer.Intermediate_Count
' -- First item is special case, the others are just diference between i and i-1
timeDelta = IIf(i = 1, myTimer.Intermediate_Get(1), myTimer.Intermediate_Get(i)-myTimer.Intermediate_Get(i-1))

' -- Frame rate is inverse of timeDelta, but we better check the division by zero :)
frameRate = IIf(timeDelta = 0, "N/A", Format$(1/timeDelta, "#.0"))

' -- Lets build the report
sOut += "#" + Format$(i) + $TAB + Format$(timeDelta*1000, "#.00") + $TAB + frameRate + $CRLF
Next

MsgBox 0, sOut, %MB_ICONINFORMATION, "Measured frame characteristics"



Petr

ErosOlmi
29-06-2011, 21:20
Thanks a lot Petr.

That class is just at the beginning. A lot of new features can be added quite easily.
If you have ideas or requests just let me know.

Ciao
Eros