Timing Scripts - Tutorial text doesn't match example

Posted by rtaylor777 on 2010-03-04 10:59

Timing scripts
http://docs.activestate.com/activetcl/8.4/tcltutorial/Tcl39.html

The example appears to have been changed since the text refers to a variable k and talks about multiplication.

Text:
=====================================================================
After you've run the example, play with the size of the loop counters in timetst1 and timetst2. If you make the inner loop counter 5 or less, it may take longer to execute timetst2 than it takes for timetst1. This is because it takes time to calculate and assign the variable k, and if the inner loop is too small, then the gain in not doing the multiply inside the loop is lost in the time it takes to do the outside the loop calculation.
=====================================================================

Example:
=====================================================================
proc timetst1 {lst} {
set x [lsearch $lst "5000"]
return $x
}

proc timetst2 {array} {
upvar $array a
return $a(5000);
}

# Make a long list and a large array.
for {set i 0} {$i < 5001} {incr i} {
set array($i) $i
lappend list $i
}

puts "Time for list search: [ time {timetst1 $list} 10]"
puts "Time for array index: [ time {timetst2 array} 10]"
=====================================================================
Thank you.