Re: TclX loop slow in the default case



Alexandre Ferrieux wrote:
Also, can you explain why the cheats are still 3.75 times behind naked
[for] (see Evil Son's post) ?

At an (informed) guess, because the variables still aren't being bound
directly to local variable table indices (though the LVT indices may
be being stored in the internal representation of the variable names)
and that forces time to be spent parsing variables and dealing with
hash tables. This is because the loop variable in the test harness
isn't actually being assigned a slot in the LVT at all.

Using (a corrected version of) Miguel's cheatloop2, I get this:

% proc c2 {} {cheatloop2 x 0 10000 {}}
% time c2 1000
2078.150919 microseconds per iteration
% proc c2 {} {set x {}; cheatloop2 x 0 10000 {}}
% time c2 1000
712.200715 microseconds per iteration

For comparison:

% proc floop {} {for {set x 0} {$x<10000} {incr x} {}}
% time floop 1000
636.676754 microseconds per iteration

Not bad given that you've got the overhead of dynamic programming!

(Also note that the disassembly of the thing generated inside
[cheatloop2] is different in the two cases. Remember to put the probe
after the [uplevel] call if you're testing this yourself.)

Donal.
.



Relevant Pages