Created
April 18, 2011 16:10
-
-
Save ernie/925618 to your computer and use it in GitHub Desktop.
Benchmark for grouping optimization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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