Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Comparing how to do a reverse sort
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! }
# 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
You can’t perform that action at this time.