Skip to content

Instantly share code, notes, and snippets.

@ugisozols
Created December 3, 2010 11:23
Show Gist options
  • Save ugisozols/726844 to your computer and use it in GitHub Desktop.
Save ugisozols/726844 to your computer and use it in GitHub Desktop.
Benchmark.bmbm do |x|
x.report("each") do
count = 0
self.posts.each do |p|
count += 1 if p.live?
end
count
end
x.report("select") { posts.select(&:live?).count }
end
================================================================
Rehearsal ------------------------------------------
each 0.010000 0.000000 0.010000 ( 0.007944)
select 0.000000 0.000000 0.000000 ( 0.000321)
--------------------------------- total: 0.010000sec
user system total real
each 0.010000 0.000000 0.010000 ( 0.015396)
select 0.000000 0.000000 0.000000 ( 0.000409)
================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment