Created
February 22, 2013 19:15
-
-
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.
This file contains hidden or 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
# | |
# 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