Time a function: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 530: Line 530:
=== Using QueryPerformanceCounter ===
=== Using QueryPerformanceCounter ===
QueryPerformanceCounter allows even more precision:
QueryPerformanceCounter allows even more precision:
<lang AHK>MsgBox % time("fx")
<lang AHK>MsgBox, % TimeFunction("fx")


TimeFunction(Function, Parameters*) {
time(function, parameter=0){
SetBatchLines, -1 ; SetBatchLines sets the speed of which every new line of coe is run.
SetBatchLines -1
DllCall("QueryPerformanceCounter", "Int64*", CounterBefore)
DllCall("QueryPerformanceCounter", "Int64*", CounterBefore) ; Start the counter.
DllCall("QueryPerformanceFrequency", "Int64*", Freq)
DllCall("QueryPerformanceFrequency", "Int64*", Freq) ; Get the frequency of the counter.
Function.Call(Parameters*) ; Call the function with it's parameters.
%function%(parameter)
DllCall("QueryPerformanceCounter", "Int64*", CounterAfter)
DllCall("QueryPerformanceCounter", "Int64*", CounterAfter) ; End the counter.

return (CounterAfter-CounterBefore)/Freq * 1000 " milliseconds"
; Calculate the speed of which it counted.
Return, (((CounterAfter - CounterBefore) / Freq) * 1000) . " milliseconds."
}
}


fx(){
fx() {
Sleep 1000
Sleep, 1000
}</lang>
}</lang>