I think your second version will be very slow if there are only negative numbers... ;) My version below is reasonably fast if there is no zero in the input, otherwise it fails:
hdb => sub { my @list = @input; @list = sort{$a*$b>0?$a<=>$b:$b<=>$a} @list; Compare(\@list,\@output) or die "@list" if DO_CHECK; },
In reply to Re^2: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1
by hdb
in thread Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1
by haukex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |