note
eric256
<p>I played around and it seems that creating the copies is where a lot of time is lost in the second version causeing it to be slow. So i moved the processing out of the map and into a function, the cached results out of it, and used that for the sort. Makes it appear about the same speed as the first sort, not positive the best way to benchmark in perl6 yet though.
</p>
<code>
my %cache;
sub pre_process($word) {
unless %cache.exists($word) {
%cache{$word} = $word.subst(/(\d+)/, -> $/{ sprintf( "%s%c%s",0 , $0.chars, $0)}, :g).lc;
}
return %cache{$word};
}
sub natural_cmp ($a, $b) {
return (pre_process($a) cmp pre_process($b));
}
</code>
<div class="pmsig"><div class="pmsig-263384">
<br />___________<br />
Eric Hodges
</div></div>
856304
856304