Created
July 15, 2012 02:05
-
-
Save desmondmonster/3114439 to your computer and use it in GitHub Desktop.
active hash benchmark script
This file contains 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 '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