All pastes #333573 Raw Edit

Something

public text v1 · immutable
#333573 ·published 2007-01-30 23:51 UTC
rendered paste body
SuperStrict


'Demo:


Global Counter:TPerfCounter=TperfCounter.Create(1000000000) 'Create a Nano-Counter.

counter.Start()	'Start the counter.
Global MS:Int=MilliSecs()
Repeat
	Print Counter.Stop()+"  "+(MilliSecs()-ms)/1000	'test counter by checking it next to millisecs.
Until (MilliSecs()-ms)>10000 'do it for 10 secs.

End	'  XD I wonder what this does...










'--------------------------------------- the real timer lib:

Extern "win32"
	Function QueryPerformanceFrequency(LARGE_INTEGER:Long Var)
	Function QueryPerformanceCounter(LARGE_INTEGER:Long Var)
EndExtern


Type TPerfCounter
	Field Frequency:Double
	Field basefrequency:Long
	Field Started:Long
	Field LastValue:Long
	Global perfTime:Long	'Global to the type so that a new Local variable doesnt get created
							'in every function/method. Slight speed increase.
							
	Function GetCounter:Long()	'Calls QueryPerformanceCounter directly.
		QueryPerformanceCounter(PerfTime)
		Return PerfTime
	End Function

	
	Function Create:TPerfCounter(Freq:Long)	'Creates a Performance Counter using the Frequency
		Local obj:TPerfCounter=New TPerfCounter
		obj.frequency=Freq
		QueryPerformanceFrequency(obj.baseFrequency)
		obj.Frequency=(obj.basefrequency/obj.Frequency)
		Return OBJ
	End Function

	Method GetTicks:Long()					'Get this counter's ticks (uses Frequency)
		QueryPerformanceCounter(PerfTime)
		Return perftime/frequency
	End Method

	Method Start()	'Start this counter. (Actually, just set its Started property....)
		QueryPerformanceCounter(PerfTime)
		Started=perfTime
	End Method
	
	Method Stop:Long()	'Stop the counter and return the amount of ticks.
		QueryPerformanceCounter(PerfTime)
		LastValue=Long((perftime-Started)/Frequency)
		Return LastValue
	End Method
End Type