Last active
June 10, 2016 22:13
-
-
Save mohnish/8eaeae84609481fae233 to your computer and use it in GitHub Desktop.
benchmark for find in batches
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/ips' | |
| Benchmark.ips do |x| | |
| x.config(:time => 5, :warmup => 2) | |
| x.report("select in batches and lookup using the id") do | |
| User.find_in_batches(:conditions => ["updated_at > ?", 8.weeks.ago.to_s(:db)], :select => :id) do |users| | |
| users.map { |user| User.find(user.id, :include => [:user_metric]).id } | |
| end | |
| end | |
| x.report("lookup in batches") do |times| | |
| User.find_in_batches(:conditions => ["updated_at > ?", 8.weeks.ago.to_s(:db)], :include => [:user_metric]) do |users| | |
| users.map { |user| user.id } | |
| end | |
| end | |
| x.compare! | |
| 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
| Calculating ------------------------------------- | |
| select in batches and lookup using the id | |
| 20.000 i/100ms | |
| lookup in batches 36.000 i/100ms | |
| ------------------------------------------------- | |
| select in batches and lookup using the id | |
| 266.158 (±39.8%) i/s - 1.060k | |
| lookup in batches 21.686k (±12.7%) i/s - 64.728k | |
| Comparison: | |
| lookup in batches: 21686.5 i/s | |
| select in batches and lookup using the id: 266.2 i/s - 81.48x slower |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation