<span style="font-family: courier new,monospace;">I just thought I'd follow up on the discussion I started last week.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(Thanks to all who participated!)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Attached is my current version of the test harness based on</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Abram's work, and most if not all supplied routines and</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">suggestions (even your's Uri, now that I had the time to</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">look!)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">My conclusions:</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">1/ Abram's 'nounpacksort' was the most efficient.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">2/ Uri's rehash of my original code wins as the most readable.<br> (I know it had ugly 'C' constructs, but I couldn't think of a better<br> more Perl'ish way (see bonus points below))<br>
3/ My original code wasn't all that bad :-)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">4/ Adding the tuple idea yields noticeable improvements.</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Uri also gets bonus points for showing me that I could do this</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">kind of in-place substitution... on a list:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> s/ //g foreach @oids;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Uri also gets extra bonus points for teaching me to use<br>regex's with embedded code. I always knew it could be done<br>but never spent the time to learn it, nor recognize when<br>
it would be useful. Now (dammit), thanks to Uri, I know.<br><br> s/(\d+)/sprintf('%8s', $1)/ge foreach @oids;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">And oh yes... printing the 'number as a string' _is_ faster<br>than printing a 'number as a number'!<br><br>Here's the benchmark results:<br><br> s/iter Improvement<br>
abram_whilecmp 7.05 --<br>indy_slow_sort 6.89 2%<br>henrys_sort 5.52 28%<br>fulko_sort_uri 1.79 294%<br>fulko_sort_orig 1.77 299%<br>
abram_swartzpacksort 1.55 356%<br>abram_packsort 1.41 400%<br>fulko_sort 1.14 519%<br>abram_nounpacksort 0.905 679%<br><br>Oh... another thing I learned...</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">When running benchmarks... turn off Centrino auto-CPU-speed-mechanism!<br>I was having a hell of a time trying to figure out<br>
why my results were always all over the map. :-(</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Finally, for those who want to see the (current) winners,<br>
without having to look at the attachment, they are:</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">For Readability:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">sub fulko_sort_uri {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> my @oids = @_;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> s/(\d+)/sprintf('%8s', $1)/ge foreach @oids;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> @oids = sort @oids;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> s/ //g foreach @oids;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return @oids;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">For Fastest:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">sub abram_nounpacksort {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> my @data = map { [ split(/\./, $_) ] } @_;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> my @sorted = map { $_->[1] }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> sort { $a->[0] cmp $b->[0] }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> map { [pack("N*",@$_),$_] } @data;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> @sorted = map { join(".",@$_) } @sorted;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return @sorted;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">