Can someone explain this performance issue?



Hi,

I have a proc to splice together n lists, creating a list that
contains [lindex $list1 0] [lindex $list2 0] ... [lindex $list-n 0]
[lindex $list1 1] ... etc.

I have a fairly decent microbenchmark that constructs around 1000
lists of 10-20 elements each (each element is a different md5 hash in
hex format), and then splices together pairs from this set of lists.
In total I time {} about 25000 splice operations to get the benchmark.

If I run the code below as-is, the second benchmark run gives around
48000 micros per iteration (for pairs of lists).

If I run the code with the "set iterscript" uncommented, I get around
36500 micros per iteration.

proc ::listx::splice2 {args} {

set varcounter 0
set iterscript "lappend list_S"
set eachspec [list]

foreach arg $args {
set v "v[incr varcounter]"
append iterscript " \$$v"
lappend eachspec $v $arg
}

# set iterscript "lappend list_S \$v1 \$v2"

set list_S [list]

foreach {*}$eachspec $iterscript


return $list_S
}

Needless to say I have checked that the iterscript I build and the one
I define are identical - in fact I can add an if { $iterscript_built
ne $iterscript } { error DIE } to that code and it will run happily.

Does anyone have any wisdom on this apparently bizarre situation?

In case it matters my tcl_patchLevel is 8.5a6. Yes, I'm planning to
upgrade ;p

Regards,
Twylite
.


Quantcast