Go to the source code of this file.
Functions/Subroutines | |
global BENCH bench ret | bench_tmpfile () |
ret | bench_rm (type args) |
ret | bench (type args) |
ret | usage () |
ret bench | ( | type | args | ) |
Definition at line 192 of file libbench.tcl.
References error(), global(), and time.
00192 { 00193 global BENCH bench errorInfo errorCode 00194 00195 # -pre script 00196 # -body script 00197 # -desc msg 00198 # -post script 00199 # -ipre script 00200 # -ipost script 00201 # -iterations <#> 00202 array set opts { 00203 -pre {} 00204 -body {} 00205 -desc {} 00206 -post {} 00207 -ipre {} 00208 -ipost {} 00209 } 00210 set opts(-iter) $BENCH(ITERS) 00211 while {[llength $args]} { 00212 set key [lindex $args 0] 00213 switch -glob -- $key { 00214 -res* { set opts(-res) [lindex $args 1] } 00215 -pr* { set opts(-pre) [lindex $args 1] } 00216 -po* { set opts(-post) [lindex $args 1] } 00217 -ipr* { set opts(-ipre) [lindex $args 1] } 00218 -ipo* { set opts(-ipost) [lindex $args 1] } 00219 -bo* { set opts(-body) [lindex $args 1] } 00220 -de* { set opts(-desc) [lindex $args 1] } 00221 -it* { 00222 # Only change the iterations when it is smaller than 00223 # the requested default 00224 set val [lindex $args 1] 00225 if {$opts(-iter) > $val} { set opts(-iter) $val } 00226 } 00227 default { 00228 error "unknown option $key" 00229 } 00230 } 00231 set args [lreplace $args 0 1] 00232 } 00233 if {($BENCH(MATCH) != "") && ![string match $BENCH(MATCH) $opts(-desc)]} { 00234 return 00235 } 00236 if {($BENCH(RMATCH) != "") && ![regexp $BENCH(RMATCH) $opts(-desc)]} { 00237 return 00238 } 00239 if {$opts(-pre) != ""} { 00240 uplevel \#0 $opts(-pre) 00241 } 00242 if {$opts(-body) != ""} { 00243 # always run it once to remove compile phase confusion 00244 if {$opts(-ipre) != ""} { 00245 uplevel \#0 $opts(-ipre) 00246 } 00247 set code [catch {uplevel \#0 $opts(-body)} res] 00248 if {$opts(-ipost) != ""} { 00249 uplevel \#0 $opts(-ipost) 00250 } 00251 if {!$code && [info exists opts(-res)] \ 00252 && [string compare $opts(-res) $res]} { 00253 if {$BENCH(ERRORS)} { 00254 return -code error "Result was:\n$res\nResult\ 00255 should have been:\n$opts(-res)" 00256 } else { 00257 set res "BAD_RES" 00258 } 00259 set bench($opts(-desc)) $res 00260 puts $BENCH(OUTFID) [list Sourcing "$opts(-desc): $res"] 00261 } else { 00262 if {($opts(-ipre) != "") || ($opts(-ipost) != "")} { 00263 00264 # We do the averaging on our own, to allow untimed 00265 # pre/post execution per iteration. We catch and 00266 # handle problems in the pre/post code as if 00267 # everything was executed as one block (like it would 00268 # be in the other path). We are using floating point 00269 # to avoid integer overflow, easily happening when 00270 # accumulating a high number (iterations) of large 00271 # integers (microseconds). 00272 00273 set total 0.0 00274 for {set i 0} {$i < $opts(-iter)} {incr i} { 00275 set code 0 00276 if {$opts(-ipre) != ""} { 00277 set code [catch {uplevel \#0 $opts(-ipre)} res] 00278 if {$code} break 00279 } 00280 set code [catch {uplevel \#0 [list time $opts(-body) 1]} res] 00281 if {$code} break 00282 set total [expr {$total + [lindex $res 0]}] 00283 if {$opts(-ipost) != ""} { 00284 set code [catch {uplevel \#0 $opts(-ipost)} res] 00285 if {$code} break 00286 } 00287 } 00288 if {!$code} { 00289 set res [list [expr {int ($total/$opts(-iter))}] microseconds per iteration] 00290 } 00291 } else { 00292 set code [catch {uplevel \#0 \ 00293 [list time $opts(-body) $opts(-iter)]} res] 00294 } 00295 if {!$BENCH(THREADS)} { 00296 if {$code == 0} { 00297 # Get just the microseconds value from the time result 00298 set res [lindex $res 0] 00299 } elseif {$code != 666} { 00300 # A 666 result code means pass it through to the bench 00301 # suite. Otherwise throw errors all the way out, unless 00302 # we specified not to throw errors (option -errors 0 to 00303 # libbench). 00304 if {$BENCH(ERRORS)} { 00305 return -code $code -errorinfo $errorInfo \ 00306 -errorcode $errorCode 00307 } else { 00308 set res "ERR" 00309 } 00310 } 00311 set bench($opts(-desc)) $res 00312 puts $BENCH(OUTFID) [list Sourcing "$opts(-desc): $res"] 00313 } else { 00314 # Threaded runs report back asynchronously 00315 thread::send $BENCH(us) \ 00316 [list thread_report $opts(-desc) $code $res] 00317 } 00318 } 00319 } 00320 if {($opts(-post) != "") && [catch {uplevel \#0 $opts(-post)} err] \ 00321 && $BENCH(ERRORS)} { 00322 return -code error "post code threw error:\n$err" 00323 } 00324 return 00325 }
ret bench_rm | ( | type | args | ) |
Definition at line 150 of file libbench.tcl.
References file().
00150 { 00151 foreach file $args { 00152 if {[info tclversion] > 7.4} { 00153 catch {file delete $file} 00154 } else { 00155 catch {exec /bin/rm $file} 00156 } 00157 } 00158 }
global BENCH bench ret bench_tmpfile | ( | ) |
Definition at line 122 of file libbench.tcl.
References file(), and global().
00122 { 00123 global tcl_platform env BENCH 00124 if {![info exists BENCH(uniqid)]} { set BENCH(uniqid) 0 } 00125 set base "tclbench[incr BENCH(uniqid)].dat" 00126 if {[info exists tcl_platform(platform)]} { 00127 if {$tcl_platform(platform) == "unix"} { 00128 return "/tmp/$base" 00129 } elseif {$tcl_platform(platform) == "windows"} { 00130 return [file join $env(TEMP) $base] 00131 } else { 00132 return $base 00133 } 00134 } else { 00135 # The Good Ol' Days (?) when only Unix support existed 00136 return "/tmp/$base" 00137 } 00138 }
ret usage | ( | ) |
Definition at line 327 of file libbench.tcl.
References file().
00327 { 00328 set me [file tail [info script]] 00329 puts stderr "Usage: $me ?options?\ 00330 \n\t-help # print out this message\ 00331 \n\t-rmatch <regexp> # only run tests matching this pattern\ 00332 \n\t-match <glob> # only run tests matching this pattern\ 00333 \n\t-interp <name> # name of interp (tries to get it right)\ 00334 \n\t-thread <num> # number of threads to use\ 00335 \n\tfileList # files to benchmark" 00336 exit 1 00337 }