This page is intended to document issues when effective execution of Tcl scripts is targeted. Please add any single topic below as to keep it as a comprehensive list. Append general comments as usual to the end of this page -- RJM.
See also Tcl Performance, Tk Performance
(*) This bug has been fixed in tcl8.5a2
RJM: Referencing to (2) I can say that I found this by accident. On a Win98 machine with 266 MHz clock, the following execution times apply:
An empty proc without Arguments:
% proc test {} {} % time {test} 1000 95 microseconds per iteration
An empty proc with an Argument:
% proc fast {x} {} % time {fast 5} 1000 12 microseconds per iteration
I performed several variations, also with filled body and so on. The crucial differencs lies in defining a proc with or without an argument.
MSW: Actually calling a proc without an argument. For comparison:
% time {test} 1000 12 microseconds per iteration % time {fast 5} 1000 3 microseconds per iteration % proc maybe {{empty {}}} {} % time {maybe} 1000 13 microseconds per iteration % time {maybe empty} 1000 3 microseconds per iteration
MS This is Bug #458361 [L2 ], but the interpretation is wrong: it is not proc calls without arguments that are slow, but rather scripts that consist of a single word and whose string equals a command name - which significantly reduces the likelihood of hitting the bug. Even adding a space to the script destroys the effect. Witness
% proc maybe {{empty {}}} {} % # call with argument % time {maybe empty} 10000 4 microseconds per iteration % # call without argument % time {maybe} 10000 19 microseconds per iteration % # call without argument; space added % time {maybe } 10000 3 microseconds per iteration % # call without argument; semicolon added % time {maybe;} 10000 4 microseconds per iteration % complex script, call with arguments % time {maybe empty; maybe empty} 10000 7 microseconds per iteration % # complex script, call without arguments % time {maybe;maybe} 10000 7 microseconds per iteration
Thanks, I have updated the issue list above accordingly --RJM
I revised your update; hope you agree with the revision. Saving your previous version here if you want to restore it - delete if not needed. -- MS Hmm, I was a bit tackled by the usage of the time command to test the performance. In normal calls the problem will not occur, since it truly depends on any extra character before or after the command name (also newline). So, practically the problem will not arise that often. But being aware of it is good. -- RJM
DKF: This is a shimmering effect between command names and scripts.
RJM: Ah, the link to Performance on top of this page has been added by anybody. Fine, prior to creating this page, I did search the wiki page titles for the phrase "speed", not "performance". However, I believe this page might serve as a summarization of issues with significant speed impact and quite common usage in scripts.
RJM: Referencing to (4), examples follow that document the time command problem inside procs.
# "procless" loop % time {for {set n 0} {$n < 100000} {incr n} {set x $n}} 1378209 microseconds per iteration % proc a {} {for {set n 0} {$n < 100000} {incr n} {set x $n}} % time a 250852 microseconds per iteration % proc b {} {time {for {set n 0} {$n < 100000} {incr n} {set x $n}}} % b 1132636 microseconds per iteration