On Saturday, June 9, 2018 at 11:59:05 AM UTC+2, Cecil Westerhof wrote:
> I decided to write a proc to make timing more easy to do:
>
http://wiki.tcl.tk/55368
> As always: comments, tips, questions and requests are appreciated.
[time] accepts zero iterations, and Tcl built-ins were improved to "do nothing gracefully"[1]. There is no reason to bail out.
The output of [time] already is an average. There is no reason to introduce more passes (I'd prefer this term over "tries" here.). If you liked more convenience, then provide [expr] in your call to [time $code [expr $iterations]]. This allows invocation [doTime $code 1000*5].
My third comment is about the context. You could do sth like
[uplevel 1 [list time $code [uplevel 1 [list expr $iterations]]]] ;# untested
I.e. resolve everything in the caller's context. This allows using doTime from others than the global context. And it allows using variables in $iterations.
# untested
namespace eval foo {
variable iterations 1000
variable passes 5
proc bar args {# do bar}
proc time_bar {} {
variable iterations
variable passes
# the uplevel of expr is not even needed for this use case ...
doTime bar $iterations*$passes
# ... but for this fancy code.
doTime bar {$iterations*[incr passes]}
}
}
[1]
https://core.tcl.tk/tips/doc/trunk/tip/323.md