Skip to content

Instantly share code, notes, and snippets.

@ernie
Created April 18, 2011 16:10
Show Gist options
  • Save ernie/925618 to your computer and use it in GitHub Desktop.
Save ernie/925618 to your computer and use it in GitHub Desktop.
Benchmark for grouping optimization
require 'benchmark'
$LOAD_PATH << './lib'
require 'arel'
def grouping_any(range)
literal = Arel.sql('1')
literal.eq_any(range.to_a)
end
def grouping_all(range)
literal = Arel.sql('1')
literal.eq_all(range.to_a)
end
Benchmark.bm(7) do |x|
x.report("grouping any") do
10000.times do |i|
grouping_any(1..100)
end
end
x.report("grouping all") do
10000.times do |i|
grouping_all(1..100)
end
end
end
BEFORE:
user system total real
grouping any 1.190000 0.000000 1.190000 ( 1.190089)
grouping all 1.300000 0.010000 1.310000 ( 1.408396)
AFTER:
user system total real
grouping any 1.140000 0.010000 1.150000 ( 1.155710)
grouping all 0.650000 0.000000 0.650000 ( 0.664369)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment