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% --
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1
by Veltro (Hermit) on Feb 05, 2019 at 18:04 UTC | |
Re^2: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1
by Eily (Monsignor) on Feb 06, 2019 at 10:48 UTC |
In Section
Seekers of Perl Wisdom