Fasterer: Enumerable#sort is slower

Enumerable#sort is slower than Enumerable#sort_by
This commit is contained in:
Reinier Balt 2015-08-19 15:19:47 +02:00
parent 5092b388fe
commit 405ad5a79f
2 changed files with 2 additions and 2 deletions

View file

@ -22,7 +22,7 @@ module Stats
def find_top10_longest_running_projects
projects = user.projects.order('created_at ASC')
projects.sort{|a,b| b.running_time <=> a.running_time}.take(10)
projects.sort_by{ |p| p.running_time }.take(10)
end
end

View file

@ -34,7 +34,7 @@ class User < ActiveRecord::Base
}
end
def projects_in_state_by_position(state)
self.sort{ |a,b| a.position <=> b.position }.select{ |p| p.state == state }
self.sort_by{ |p| p.position }.select{ |p| p.state == state }
end
def next_from(project)
self.offset_from(project, 1)