http://www.perlmonks.org?node_id=1229411


in reply to Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1

Using the fact that a negative value read as an unsigned is bigger than any signed positive:

eily => sub { my @list = -50..50; @list = sort { ~$b <=> ~$a } @list; Compare(\@list,[0..50,-50..-1]) or die "@list" if DO_CHECK; }
Rate grepfirst sortfirst eily grepfirst 59577/s -- -14% -32% sortfirst 69292/s 16% -- -21% eily 87583/s 47% 26% --