Skip to content

Instantly share code, notes, and snippets.

@anoved
Created February 22, 2013 19:15
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 anoved/5015831 to your computer and use it in GitHub Desktop.
Save anoved/5015831 to your computer and use it in GitHub Desktop.
A procedure to perform ballpark performance benchmarking of Tcl scripts. It is a simple alternative to the `bench` package in Tcllib.
#
# Parameters:
# script, the code to benchmark. Executed in caller's context.
# iterations, number of times to execute script. Defaults to 1.
#
# Returns:
# a two-element list reporting the average iteration time to execute script
# and the total elapsed time in microseconds.
#
proc benchmark {script {iterations 1}} {
set start [clock microseconds]
set average [uplevel 1 [list time $script $iterations]]
set end [clock microseconds]
set total [expr {$end - $start}]
return [list [lindex $average 0] $total]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment