enumerable sort vs sort_by
aaronmgdr opened this issue · 4 comments
aaronmgdr commented
noticed that in the test for enumerable sort vs sort_by sort_by
uses symbol.to_proc
while sort
uses a block. wouldn't this effect the results since another tests shows symbol to proc is faster than block?
JuanitoFatas commented
ARRAY.sort { |a, b| a.name <=> b.name }
I don't know how to make sort
example in Symbol#to_proc
form. So have to use sort
this way to archieve same result with sort_by
.
aaronmgdr commented
yeah i don't think you can change sort
but sort_by
maybe
def fast
ARRAY.sort_by { |a| a.name }
end
JuanitoFatas commented
I added e20d448 for fair comparison. Thanks for bring this up! 👍
aaronmgdr commented
you're welcome