TclX loop slow in the default case
- From: Evil Son <ewilsonmail@xxxxxxxxx>
- Date: Tue, 26 Aug 2008 14:02:41 -0700 (PDT)
Hello
I wanted to see how much faster the Tclx loop command was compared to
the ordinary for loop.
When [loop] is used without an explicit increment, it defaults to 1.
I noticed that this default case runs very slowly.
Here is my script:
ed@aleph> cat loop.tcl
# timing "for" and the Tclx "loop"
package require Tclx
proc loop_default {lim} {
loop i 0 $lim {}
}
proc loop_explicit {lim} {
loop i 0 1 $lim {}
}
proc tcl_for {lim} {
for {set i 0} {$i<$lim} {incr i} {}
}
proc run {lim} {
puts "time (us) taken for $lim iterations"
puts "[lindex [time {loop_default $lim}] 0]\t\
<-- TclX 'loop' with default increment"
puts "[lindex [time {loop_explicit $lim}] 0]\t\
<-- TclX 'loop' with explicit increment"
puts "[lindex [time {tcl_for $lim}] 0]\t\ <-- tcl 'for'"
}
if {[info script] eq $argv0 } {
puts "tclsh: [info patchlevel]"
puts "Tclx: [package require Tclx]"
set lim [lindex $argv 0]
run $lim
}
# end ----------------------------------------------------
I tested the script with different values for the iterations/limit 9
times per limit and took the median value. I tested with tcl 8.4 and
8.5.
ed@aleph>
ed@aleph> tclsh8.5 loop.tcl 10 > out.txt
ed@aleph> tclsh8.5 run-tests.tcl 100 >> out.txt
ed@aleph> tclsh8.5 run-tests.tcl 1000 >> out.txt
ed@aleph> tclsh8.5 run-tests.tcl 10000 >> out.txt
ed@aleph> cat out.txt
tclsh: 8.5.3
Tclx: 8.4
time (us) taken for 10 iterations
66 <-- TclX 'loop' with default increment
34 <-- TclX 'loop' with explicit increment
47 <-- tcl 'for'
8.4.18 8.5.3 %chng proc
23 21 -0.02 tcl_for
62 172 1.10 loop_default
7 9 0.02 loop_explicit
8.4.18 8.5.3 %chng proc
200 174 -0.26 tcl_for
561 1605 10.44 loop_default
7 9 0.02 loop_explicit
8.4.18 8.5.3 %chng proc
1961 1700 -2.61 tcl_for
5525 16539 110.14 loop_default
7 10 0.03 loop_explicit
ed@aleph>
Is this a bug for the default increment case?
Regards
Evilson
.
- Follow-Ups:
- Re: TclX loop slow in the default case
- From: miguel
- Re: TclX loop slow in the default case
- From: Alexandre Ferrieux
- Re: TclX loop slow in the default case
- Prev by Date: Re: osx wish foreground issue
- Next by Date: Re: record usage in tcl
- Previous by thread: ActiveTcl version on Windows XP
- Next by thread: Re: TclX loop slow in the default case
- Index(es):
Relevant Pages
|