Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@davebrny
Last active February 12, 2017 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davebrny/0b34db1c2c0db78c4b3bb4d23ba26a9a to your computer and use it in GitHub Desktop.
Save davebrny/0b34db1c2c0db78c4b3bb4d23ba26a9a to your computer and use it in GitHub Desktop.
(autohotkey) - a_tickCount or "QueryPerformanceCounter" timer
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
*/
@davebrny
Copy link
Author

davebrny commented Feb 12, 2017

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_start("total")  
sleep 1000 
timer_start("timer 2")  
sleep 500 
time2 := timer_stop("timer 2")  
total := timer_stop("total", "qpc")  

msgBox, %total% `n%time2%  

timer types

  • a_tickCount timer

timer_stop("name", "0")
timer_stop("name")   (or leave blank)

timer_stop("name", "1")
timer_stop("name", "qpc")

 


sublime snippetstimerstart, timerstop


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment