Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Making Timing More Easy

42 views
Skip to first unread message

Cecil Westerhof

unread,
Jun 9, 2018, 5:59:05 AM6/9/18
to
Because of the discussion about what would be more efficient for my
proc splitOnWhiteSpace:
http://wiki.tcl.tk/55362

I decided to write a proc to make timing more easy to do:
http://wiki.tcl.tk/55368

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Mike Griffiths

unread,
Jun 9, 2018, 4:36:23 PM6/9/18
to
What would you say the benefit is of this over just using [time]?

Cecil Westerhof

unread,
Jun 10, 2018, 12:59:04 AM6/10/18
to
Mike Griffiths <mi...@keyboardzombie.com> writes:

> On Saturday, 9 June 2018 10:59:05 UTC+1, Cecil Westerhof wrote:
>> Because of the discussion about what would be more efficient for my
>> proc splitOnWhiteSpace:
>> http://wiki.tcl.tk/55362
>>
>> I decided to write a proc to make timing more easy to do:
>> http://wiki.tcl.tk/55368
>
> What would you say the benefit is of this over just using [time]?

That I can do something like:
set regexTime [doTime "splitOnWhiteSpace {${currentStr}}" \
${iterations} ${tries}]

and if I only want the average and no output:
set regexTime [doTime "splitOnWhiteSpace {${currentStr}}" \
${iterations} ${tries} False]

and because I want to know the timings of both I also do:
set tclTime [doTime "splitOnWhiteSpace {${currentStr}} -1 -1 True" \
${iterations} ${tries}]


For one reason or another I really like DRY.

heinrichmartin

unread,
Jun 11, 2018, 3:43:38 AM6/11/18
to
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
0 new messages