Re: TclX loop slow in the default case
- From: Evil Son <ewilsonmail@xxxxxxxxx>
- Date: Wed, 27 Aug 2008 20:02:58 -0700 (PDT)
On Aug 28, 11:03 am, "Donal K. Fellows" <donal.k.fell...@xxxxxxxxx>
wrote:
Alexandre Ferrieux wrote:
Why a wrong analysis ? How would you define [loop] in pure Tcl so that
it has the same performance as a [for] ?
In 8.5 and before, you can't because the body script will not be
compiled to have efficient access to local variables. (This might
change in 8.6 AIUI.) But apart from that you can get close:
proc loop {var from to body} {
upvar 1 $var v
for {set v $from} {$v <= $to} {incr v} {
uplevel 1 $body
}
}
Yes, that's probably the sort of thing you'd write naïvely. That will
use maximally efficient variable accesses (except in the body at the
moment because we don't currently reconnect the compilation of the
body to the local variable table of the calling context) and will
compile the body. By contrast, the TclX loop command is actually less
efficient than that as it currently uses code that isn't very
efficient to assign the loop variables. (The API it uses is optimized
for ease of use with literal variable names, not for execution speed.)
Donal.
Funny you mention it, I had indeed written the naive implementation as
an exercise :-) I had gotten the following results for counting: 0 --
10,000-1
ed@aleph> tclsh8.5 run-tests.tcl 10000
8.4.18 8.5.3 ratio proc
1960 1699 0.87 tcl_for
5481 16175 2.95 loop_default
9020 11777 1.31 loop_eval <-- naive implemenation
.
- Follow-Ups:
- Re: TclX loop slow in the default case
- From: Evil Son
- Re: TclX loop slow in the default case
- References:
- TclX loop slow in the default case
- From: Evil Son
- Re: TclX loop slow in the default case
- From: Alexandre Ferrieux
- Re: TclX loop slow in the default case
- From: Evil Son
- Re: TclX loop slow in the default case
- From: Donal K. Fellows
- TclX loop slow in the default case
- Prev by Date: Re: question about reset counter/data
- Next by Date: Re: TclX loop slow in the default case
- Previous by thread: Re: TclX loop slow in the default case
- Next by thread: Re: TclX loop slow in the default case
- Index(es):
Relevant Pages
|