Re: My own control structures are slow



Christian Gollwitzer <auriocus@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> writes:

> for {set x 0} {$x<=511} {incr x} {
> for {set y 0} {$y<=511} {incr y} {
> uplevel $command
> }
> }
> this works, but is very slow (2.3 seconds).
>
> My second try was to move the for loops into the upper level:
> uplevel 1 [list for {set x 0} {$x<=511} {incr x} [
> This is way faster, it takes only 0.4 seconds

It also explicitly uses "uplevel 1", which avoids shimmering.
In your first try, you keep trying to interpret $command as an integer.

Probably more important is that [uplevel] (with or without a number)
is like [eval], which converts its argument from a string to code,
which is inefficient. In your second case you do the converion just
once, instead of a quarter-million times.

> the fault seems to be that uplevel hinders bytecode compilation.

Yes. I don't know a way to change that. I doubt that it would be worthwhile
to in[tro]spect the local context ([info locals]} and duplicate it inside
a proc.... but give it a try!



--
Donald Arseneau asnd@xxxxxxxxx
.