Last active
February 12, 2017 22:50
-
-
Save davebrny/0b34db1c2c0db78c4b3bb4d23ba26a9a to your computer and use it in GitHub Desktop.
(autohotkey) - a_tickCount or "QueryPerformanceCounter" timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
timer_start(name="a"){ | |
global | |
stringReplace, name, name, % a_space, _, all | |
start_tick_%name% := a_tickCount | |
dllCall("QueryPerformanceCounter", "Int64*", start_qpc_%name%) | |
} | |
timer_stop(name="a", type=""){ | |
msg := "Timer """ name """`n- - - - - - - - - - - - - - - - - - - - - -`n`n" | |
stringReplace, name, name, % a_space, _, all | |
tick_time := a_tickCount - start_tick_%name% | |
msg .= tick_time " ms " | |
if (tick_time > 1000) | |
msg .= "(" MsToMinSec(tick_time) ")" | |
msg .= "`n`n" | |
if (type = "1") or (type = "qpc") | |
{ | |
dllCall("QueryPerformanceCounter" , "Int64*", stop_qpc_%name%) | |
dllCall("QueryPerformanceFrequency", "Int64*", timer_frequency) | |
qpc_time := stop_qpc_%name% - start_qpc_%name% | |
rounded := round( (qpc_time / timer_frequency) * 1000) | |
msg .= qpc_time / timer_frequency " (" MsToMinSec(rounded) ")`n`n" | |
} | |
return msg | |
} | |
MsToMinSec(i) { ; by polyethene | |
return, i < 1 ? "" : ((n := i // g := 60000) ? n . " min " : "") | |
. ((0 < i -= n * g) ? ((n := i // 1000) . " sec " | |
. ((i -= n * 1000) > 0 ? i . " ms" : "")) : "") | |
} | |
/* | |
[script info] | |
version = 1 | |
description = tickCount or "QueryPerformanceCounter" timer | |
author = davebrny | |
source = https://gist.github.com/davebrny/0b34db1c2c0db78c4b3bb4d23ba26a9a | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
timer
timer_start("name")
timer_stop("name" [, type])
name
the name can be left blank if using a single timer
timer_start()
to use multiple timers, use a different name for each one
timer types
timer_stop("name", "0")
timer_stop("name")
(or leave blank)timer_stop("name", "1")
timer_stop("name", "qpc")
sublime snippets ➜ timerstart, timerstop