tip457-performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tip457-perfs.tcl | |
set loops 10000000 | |
set hasArgspec [expr {![catch {info argspec specifier}]}] | |
# default implementation, no argspec, no named arguments | |
proc p1 {a b {c 0} {d 0} {e 0} {f 0} {g 0} {h 0} {i 0} {j 0}} { | |
list $a $b $c $d $e $f $g $h $i $j | |
} | |
# Tcl-pure implementation of named arguments handling | |
proc p2 {a b args} { | |
array set opt [concat {-C 0 -D 0 -E 0 -F 0 -G 0 -H 0 -I 0 -J 0} $args] | |
list $a $b $opt(-C) $opt(-D) $opt(-E) $opt(-F) $opt(-G) $opt(-H) $opt(-I) $opt | |
(-J) | |
} | |
if { $hasArgspec } { | |
# named arguments with extended argument specification | |
proc p3 {a b {c -default 0 -name C} {d -default 0 -name D} {e -default 0 -name | |
E} {f -default 0 -name F} {g -default 0 -name G} {h -default 0 -name H} {i -def | |
ault 0 -name I} {j -default 0 -name J}} { | |
list $a $b $c $d $e $f $g $h $i $j | |
} | |
# no named arguments but with extended argspec, uses new initialization code | |
proc p4 {{a -required 0} b {c 0} {d 0} {e 0} {f 0} {g 0} {h 0} {i 0} {j 0}} { | |
list $a $b $c $d $e $f $g $h $i $j | |
} | |
} | |
puts "default, 10 pos. args: [time {p1 A B 0 0 0 8 0 42 0 1} $loo | |
ps]" | |
puts "Tcl-pure, 2 pos. args, 2 named args: [time {p2 A B -J 1 -G 2} [expr $loops / 5]]" | |
if { $hasArgspec } { | |
puts "TIP-457, 2 pos. args, 2 named args: [time {p3 A B -J 1 -G 2} $loops]" | |
puts "ext-arg init code, 10 pos. args: [time {p4 A B 0 0 0 8 0 42 0 1} $loops]" | |
} | |
-------------------------------------------------------------------------------- | |
default, 10 pos. args: 0.70609 microsecs per iteration | |
Tcl-pure, 2 pos. args, 2 named args: 5.7299 microsecs per iteration [+711%] | |
TIP-457, 2 pos. args, 2 named args: 0.7266612 microsecs per iteration [+2.9%] | |
ext-arg init code, 10 pos. args: 0.7209694 microsecs per iteration [+2.1%] | |
-------------------------------------------------------------------------------- | |
default, 10 pos. args: 0.6948987 microsecs per iteration | |
Tcl-pure, 2 pos. args, 2 named args: 5.786593 microsecs per iteration [+732%] | |
TIP-457, 2 pos. args, 2 named args: 0.7150904 microsecs per iteration [+2.9%] | |
ext-arg init code, 10 pos. args: 0.7242224 microsecs per iteration [+4.2%] | |
-------------------------------------------------------------------------------- | |
default, 10 pos. args: 0.6956328 microsecs per iteration | |
Tcl-pure, 2 pos. args, 2 named args: 5.6481645 microsecs per iteration [+711%] | |
TIP-457, 2 pos. args, 2 named args: 0.706861 microsecs per iteration [+1.6%] | |
ext-arg init code, 10 pos. args: 0.692382 microsecs per iteration [-0.4%] | |
-------------------------------------------------------------------------------- | |
default, 10 pos. args: 0.6939689 microsecs per iteration | |
Tcl-pure, 2 pos. args, 2 named args: 5.625728 microsecs per iteration [+710%] | |
TIP-457, 2 pos. args, 2 named args: 0.7076775 microsecs per iteration [+2.0%] | |
ext-arg init code, 10 pos. args: 0.7052509 microsecs per iteration [+1.6%] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment