Created
May 18, 2013 14:28
-
-
Save marcandre/5604592 to your computer and use it in GitHub Desktop.
Comparing how to do a reverse sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fruity' | |
a = (1..100).to_a.shuffle | |
compare do | |
sort { a.sort{|x, y| y <=> x} } | |
sort_by { a.sort_by{|x| -x} } | |
reverse { a.sort.reverse } | |
reverse! { a.sort.reverse! } | |
end | |
# reverse! is faster than reverse by 10% ± 1.0% | |
# reverse is faster than sort_by by 6x ± 0.1 | |
# sort_by is faster than sort by 60% ± 1.0% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment