Skip to content

Instantly share code, notes, and snippets.

@oivoodoo
Created July 16, 2014 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oivoodoo/54ff23bf5699b312604e to your computer and use it in GitHub Desktop.
Save oivoodoo/54ff23bf5699b312604e to your computer and use it in GitHub Desktop.
it 'should work faster using ranges in threads on aggregate' do
Report1 = Class.new do
include Mongoid::Report
report 'example' do
attach_to Model do
group_by :day
column :field1
end
end
end
Report2 = Class.new do
include Mongoid::Report
report 'example' do
attach_to Model do
group_by :day
perform_using groups: 5, by: :day
column :field1
end
end
end
5.times do |i|
10000.times { klass.create!(day: i.days.ago, field1: 1) }
end
time1 = Benchmark.measure do
rows = scoped.ranges(day: (0.days.ago..5.days.from_now)).all
end
time2 = Benchmark.measure do
rows = scoped.all
end
puts time2
puts time1
time2.real.should > time1.real
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment