Re: TclX loop slow in the default case
- From: Evil Son <ewilsonmail@xxxxxxxxx>
- Date: Thu, 28 Aug 2008 12:14:13 -0700 (PDT)
On Aug 28, 7:32 pm, Koen Danckaert <k...@xxxxxxxxxxxxxxxx> wrote:
I think this patch is in 8.5.3, but it doesn't show up in Evilson's examples because he uses an empty loop body. Using just a minimal loop body (for example {expr {$i+5}}) gives largely different results:
tclsh: 8.4.12
time (us) taken for 10000 iterations
1157 <-- tcl 'for'
33650 <-- loop_eval
tclsh: 8.5.4
time (us) taken for 10000 iterations
1151 <-- tcl 'for'
5271 <-- loop_eval
--Koen
Indeed, I was wondering about the iteration speed. So then I put an
[expr] in the body and got:
tclsh 8.4.18
2944 naked_for
14215 tclx_loop
81158 naive_loop
23162 clever_loop <-- from Alex earlier in thread
tclsh 8.5.3
3949 naked_for
23765 tclx_loop <-- as dkf/msf expected
105259 naive_loop <-- what the!
25769 clever_loop
tclsh 8.5.4
4040 naked_for
24557 tclx_loop
17135 naive_loop <-- optimisation work kicks in as Koen/msf said.
35612 clever_loop <-- not in the 8.5.4 possible world
And just to make a fool of myself, I'll include my bug-ridden procs
#-------------------------------------------------------------
# ignore $body, we want a baseline
proc naked_for { var from to {body {}} } {
for {set var $from} {$var<$to} {incr var} {expr {$var*$var}}
}
# e.g. from dkf which responds to all the optimisation work
proc naive_loop { var from to {body {}} } {
upvar $var i
for {set i $from} {$i<$to} {incr i} {
uplevel 1 $body
}
}
#ignore body, 'loop' already has some evaluating to do
proc tclx_loop { var from to {body {}} } {
upvar $var i
loop i $from $to 1 { expr {$i*$i}}
}
# from Alex
proc clever_loop { var from to {body {}} } {
uplevel 1 [list for [list set $var $from] \
"\$$var<$to" [list incr $var] $body]
}
The procs above are called from:
#-------------------------------------------------------------
proc main {n} {
global aProcs
foreach {i} [lsort -integer [array names aProcs]] {
set proc $aProcs($i)
if {[info procs $proc] eq $proc } {
puts -nonewline [timeus [list \
$proc var 0 $n {expr {$var*$var}}]]
puts \t$proc
} else {
puts -nonewline "proc $proc currently undefined"
}
}
}
# timeus is a helper proc that does the obvious thing
Cheers
Evilson.
.
- Follow-Ups:
- Re: TclX loop slow in the default case
- From: Alexandre Ferrieux
- 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
- Re: TclX loop slow in the default case
- From: Alexandre Ferrieux
- TclX loop slow in the default case
- Prev by Date: Re: Own implementation of multithread
- Next by Date: Tcl/Tk Documentation > TclCmd > global : "info locals" issue
- 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
|