Overview
| Artifact ID: | 10e6fc7d99c5503cb414af948381916051a1250b |
|---|---|
| Ticket: | 3380073fffffffffffffffffffffffffffffffff
declining [expr] performance |
| User & Date: | cyan on 2011-07-29 01:21:34 |
Changes
- icomment:
Some interesting results: testing on my machine 8.5 and 8.6 were quite close (closer than the original bug report), but also the times reported by the "time" command disagreed quite a lot with a benchmarker I built to investigate performance in some of my code (and showed 8.6 to be faster than 8.5). Trying a few different versions of the distance proc on 8.5 and 8.6 (8.4 doesn't work on the benchmarker) (apologies for the formatting, I used vimdiff to compare the runs): namespace path {::tcl::mathop} set ::RADIAN_CONV 57.2957795131 proc distance { lat1 lon1 lat2 lon2 } { set lat1 [expr {$lat1 / $::RADIAN_CONV}] set lat2 [expr {$lat2 / $::RADIAN_CONV}] set dlon [expr {($lon2 - $lon1) / $::RADIAN_CONV}] return [expr {acos(sin($lat1) * sin($lat2) + \ cos($lat1) * cos($lat2) * cos($dlon)) * \ 6371.0}] } proc distance2 {lat1 lon1 lat2 lon2} { global RADIAN_CONV set lat1 [/ $lat1 $RADIAN_CONV] set lat2 [/ $lat2 $RADIAN_CONV] set dlon [expr {($lon2 - $lon1) / $RADIAN_CONV}] expr {acos(sin($lat1) * sin($lat2) + \ cos($lat1) * cos($lat2) * cos($dlon)) * \ 6371.0} } proc distance3 {lat1 lon1 lat2 lon2} { set lat1[/ $lat1 57.2957795131] set lat2[/ $lat2 57.2957795131] expr { acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos(($lon2 - $lon1) / 57.2957795131) ) * 6371.0 } } puts "Tcl version: [info patchlevel]" # Initial calls to ensure proc bodies are bytecode compiled, and verify correctness puts "distance: [distance 41.0 -81.0 42.0 -82.0]" puts "distance2: [distance2 41.0 -81.0 42.0 -82.0]" puts "distance3: [distance3 41.0 -81.0 42.0 -82.0]" puts "\n=========================================================" puts "distance (using time): [apply {{} {time {distance 41.0 -81.0 42.0 -82.0} 1000000}}]" puts "distance (using benchmark):" benchmark::test 1000 1000 usec distance 41.0 -81.0 42.0 -82.0 puts "\n=========================================================" puts "distance2 (using time): [apply {{} {time {distance 41.0 -81.0 42.0 -82.0} 1000000}}]" puts "distance2 (using benchmark):" benchmark::test 1000 1000 usec distance2 41.0 -81.0 42.0 -82.0 puts "\n=========================================================" puts "distance3 (using time): [apply {{} {time {distance 41.0 -81.0 42.0 -82.0} 1000000}}]" puts "distance3 (using benchmark):" benchmark::test 1000 1000 usec distance3 41.0 -81.0 42.0 -82.0 Tcl version: 8.5.9 distance: 138.92161836383994 distance2: 138.92161836383994 distance3: 138.92161836383994 ========================================================= distance (using time): 4.02733 microseconds per iteration distance (using benchmark): == testing proc (distance 41.0 -81.0 42.0 -82.0) ===== munge times: 3.432 ms llength times: 1000 descriptive parameters: min: 3.343 usec median: 3.457 usec harmonic_mean: 3.468 usec arithmetic_mean: 3.469 usec max: 4.102 usec sample_stddev: 0.069 usec 3.457 usec per iteration / 288088.464 iterations per second (1000000 iterations in 3.471 seconds) <= 3.344370 1 <= 3.370397 11 ## <= 3.384095 22 #### <= 3.397793 39 ######## <= 3.411491 86 ################# <= 3.425190 94 ################## <= 3.438888 98 ################### <= 3.452586 116 ####################### <= 3.466284 103 #################### <= 3.479983 94 ################## <= 3.493681 79 ############### 257 ################################################## ========================================================= distance2 (using time): 4.05635 microseconds per iteration distance2 (using benchmark): == testing proc (distance2 41.0 -81.0 42.0 -82.0) ===== munge times: 3.415 ms llength times: 1000 descriptive parameters: min: 2.793 usec median: 2.847 usec harmonic_mean: 2.851 usec arithmetic_mean: 2.851 usec max: 3.263 usec sample_stddev: 0.033 usec 2.847 usec per iteration / 350468.313 iterations per second (1000000 iterations in 2.853 seconds) <= 2.793661 1 <= 2.806227 15 ### <= 2.812840 40 ####### <= 2.819454 81 ############### <= 2.826067 79 ############### <= 2.832681 78 ############## <= 2.839294 95 ################# <= 2.845908 83 ############### <= 2.852521 106 ################### <= 2.859135 85 ################ <= 2.865748 65 ############ 272 ################################################## ========================================================= distance3 (using time): 4.123645 microseconds per iteration distance3 (using benchmark): == testing proc (distance3 41.0 -81.0 42.0 -82.0) ===== munge times: 3.505 ms llength times: 1000 descriptive parameters: min: 2.570 usec median: 2.620 usec harmonic_mean: 2.623 usec arithmetic_mean: 2.623 usec max: 2.894 usec sample_stddev: 0.028 usec 2.620 usec per iteration / 380933.661 iterations per second (1000000 iterations in 2.625 seconds) <= 2.570557 1 <= 2.581149 18 ### <= 2.586724 27 #### <= 2.592299 38 ###### <= 2.597873 63 ######### <= 2.603448 108 ################ <= 2.609023 93 ############## <= 2.614597 75 ########### <= 2.620172 90 ############## <= 2.625747 80 ############ <= 2.631321 74 ########### 333 ################################################## Tcl version: 8.6b1.2 distance: 138.92161836383994 distance2: 138.92161836383994 distance3: 138.92161836383994 ========================================================= distance (using time): 3.869864 microseconds per iteration distance (using benchmark): == testing proc (distance 41.0 -81.0 42.0 -82.0) ===== munge times: 2.652 ms llength times: 1000 descriptive parameters: min: 3.679 usec median: 3.812 usec harmonic_mean: 3.816 usec arithmetic_mean: 3.817 usec max: 4.391 usec sample_stddev: 0.061 usec 3.812 usec per iteration / 261862.502 iterations per second (1000000 iterations in 3.819 seconds) <= 3.680225 1 <= 3.703496 8 # <= 3.715744 3 <= 3.727992 17 ## <= 3.740240 33 ### <= 3.752488 43 #### <= 3.764736 55 ###### <= 3.776984 65 ####### <= 3.789232 92 ########## <= 3.801480 86 ######### <= 3.813728 117 ############ 480 ################################################## ========================================================= distance2 (using time): 3.821812 microseconds per iteration distance2 (using benchmark): == testing proc (distance2 41.0 -81.0 42.0 -82.0) ===== munge times: 2.623 ms llength times: 1000 descriptive parameters: min: 3.008 usec median: 3.114 usec harmonic_mean: 3.116 usec arithmetic_mean: 3.117 usec max: 3.862 usec sample_stddev: 0.048 usec 3.114 usec per iteration / 320614.862 iterations per second (1000000 iterations in 3.119 seconds) <= 3.008962 1 <= 3.027237 4 <= 3.036856 6 # <= 3.046474 8 # <= 3.056093 27 ### <= 3.065712 32 ### <= 3.075330 61 ###### <= 3.084949 57 ###### <= 3.094567 109 ########### <= 3.104186 91 ######### <= 3.113804 88 ######### 516 ################################################## ========================================================= distance3 (using time): 3.894228 microseconds per iteration distance3 (using benchmark): == testing proc (distance3 41.0 -81.0 42.0 -82.0) ===== munge times: 2.598 ms llength times: 1000 descriptive parameters: min: 2.654 usec median: 2.741 usec harmonic_mean: 2.746 usec arithmetic_mean: 2.747 usec max: 3.174 usec sample_stddev: 0.043 usec 2.741 usec per iteration / 363791.405 iterations per second (1000000 iterations in 2.749 seconds) <= 2.654868 1 <= 2.671353 3 <= 2.680029 6 # <= 2.688706 25 ### <= 2.697382 44 ##### <= 2.706058 69 ######## <= 2.714735 59 ####### <= 2.723411 81 ########## <= 2.732087 108 ############# <= 2.740764 95 ########### <= 2.749440 83 ########## 426 ################################################## - login: "cyan"
- mimetype: "text/plain"
- username: "cyan"