* meshparts <alex…@meshparts.de> | I'm thinking about the differences between two methods of passing a | list to a procedure:
>
| First one is classical:
>
| proc myproc1 {l} {} | set l [list 1 2 3] | myproc1 $l
>
| Second one uses upvar:
>
| proc myproc2 {lname} {upvar $lname l} | set l [list 1 2 3] | myproc2 l
>
| My tests show that first one is faster than second one. Since the first proc simply does nothing, and the second actually calls a command which requires some table-lookup to find the variable, a small difference in favor of #1 is to be expected. Keep in mind that only single Tcl_Obj-pointers are passed when calling the procs, either to a Tcl_ListObj in myproc1, or to a Tcl_StringObj in myproc2, so the calling overhead should be the same. | At least for lists of thousends of elements. Show the code you used for the test. I get identical times for a list of 3 elements and a list of 1000000 elements. % info patchlevel 8.6.18 % proc myproc1 {l} {} % proc myproc2 {lname} {upvar $lname l} % set l [list 1 2 3]; 1 2 3 % time {myproc1 $l} 10000 0.9285 microseconds per iteration % time {myproc1 $l} 10000 1.1559 microseconds per iteration % time {myproc1 $l} 10000 0.9241 microseconds per iteration % set l [lrepeat 1000000 1]; time {myproc1 $l} 10000 0.9497 microseconds per iteration % time {myproc1 $l} 10000 0.9398 microseconds per iteration % time {myproc1 $l} 10000 0.9357 microseconds per iteration % time {myproc1 $l} 10000 0.9527 microseconds per iteration % set l [list 1 2 3]; 1 2 3 % time {myproc2 l} 10000 1.5462 microseconds per iteration % time {myproc2 l} 10000 1.5442 microseconds per iteration % time {myproc2 l} 10000 1.5622 microseconds per iteration % set l [lrepeat 1000000 1]; time {myproc2 l} 10000 1.5281 microseconds per iteration % time {myproc2 l} 10000 1.5158 microseconds per iteration % time {myproc2 l} 10000 1.8271 microseconds per iteration Plus I wouldn't put too big faith in calling times in the microsecond region... R'