Re: Can someone explain this performance issue?





Twylite wrote:
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?

My guess at the situation:

If you set iterscript in the proc, the bytecompiler can bytecompile it
while compiling
the proc, as it is a literal expression while it
does not if you construct it at runtime. Try the new diassamble
command
from the betas to see if I'm right,

Michael

.



Relevant Pages

  • Re: Dict sharing vs. duplication
    ... n/2+1 lists, where n is the number of items. ... It also regularizes the use of lsearch which has ... uniqueness if you use the addItem proc. ... interp alias magic1 do-magic ...
    (comp.lang.tcl)
  • Re: using TCL with sqlite database...
    ... I am now able to read from and write to my database. ... is built around using lists with data... ... I'm trying to access an SQLite database via TCL. ... but fails when I open the db in proc open_sqlite_db and try to write ...
    (comp.lang.tcl)
  • Re: Effective STL Item 4 (size() vs. empty())
    ... >> Any other practical obstacle you have been encountering? ... The Osize leads to an Osplice ... source and destination lists are the same, ... to be able to keep iterators to specific items. ...
    (comp.lang.cpp)
  • Re: Adding functions to generic package
    ... Just splice the element prior to the distinguished iterator value Back: ... Why isn't there a Swap function in the library like ... the nodes on the internal linked lists of a single list container. ... The list container has both of the these operations, ...
    (comp.lang.ada)
  • Re: TIP #187:Pure Tcl implementation
    ... This is a pure Tcl TIP187 implementation in order to let interested ... programmers to play/use it. ... The input lists must be of the same length, ... proc unknown args { ...
    (comp.lang.tcl)