Re: My own control structures are slow
- From: Donald Arseneau <asnd@xxxxxxxxx>
- Date: 30 Sep 2005 00:59:28 -0700
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
.
- References:
- My own control structures are slow
- From: Christian Gollwitzer
- My own control structures are slow
- Prev by Date: Difference in 8.4/8.5 text widget - Bug or Feature
- Next by Date: Re: My own control structures are slow
- Previous by thread: Re: My own control structures are slow
- Next by thread: Re: My own control structures are slow
- Index(es):