fastruby/fast-ruby

enumerable sort vs sort_by

aaronmgdr opened this issue · 4 comments

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?

In sort example code:

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.

yeah i don't think you can change sort but sort_by maybe

def fast
  ARRAY.sort_by { |a| a.name }
end

I added e20d448 for fair comparison. Thanks for bring this up! 👍

you're welcome