Skip to content

Instantly share code, notes, and snippets.

@desmondmonster
Created July 15, 2012 02:05
Show Gist options
  • Save desmondmonster/3114439 to your computer and use it in GitHub Desktop.
Save desmondmonster/3114439 to your computer and use it in GitHub Desktop.
active hash benchmark script
require 'rubygems'
require 'benchmark'
require 'active_hash'
def test_array(size=10000)
[].tap do |array|
(1..size).each do |i|
array << { :id => i, :name => "#{i}_string", :text => "text"}
end
end
end
class HashTest < ActiveHash::Base
self.data = test_array
end
n = 1000
Benchmark.bm do |x|
x.report("10th record id") { n.times do; HashTest.find(10); end}
x.report("10th record where") { n.times do; HashTest.where(:name => "10_string"); end}
x.report("1000th record id") { n.times do; HashTest.find(1000); end }
x.report("1000th record where") { n.times do; HashTest.where(:name => "1000_string"); end}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment