Last active
August 29, 2015 14:07
-
-
Save stereodenis/c55cce82f611970ca4d1 to your computer and use it in GitHub Desktop.
benchmarks
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
# createdb bench | |
require 'pg' | |
require 'active_record' | |
require 'benchmark' | |
require 'benchmark/ips' | |
ActiveRecord::Base.establish_connection( | |
adapter: 'postgresql', | |
encoding: 'utf8', | |
username: 'postgres', | |
database: 'bench', | |
pool: 5, | |
timeout: 5000, | |
min_messages: 'warning' | |
) | |
# if you don't have a table in your db, create it like this: | |
# | |
# ActiveRecord::Schema.define do | |
# create_table :posts do |t| | |
# t.string :title | |
# end | |
# end | |
class Post < ActiveRecord::Base | |
end | |
Post.create(:title => 'title') | |
Benchmark.ips do |x| | |
x.report('all.each') do | |
Post.all.each {|p| p.title} | |
end | |
x.report('find_each') do | |
Post.find_each {|p| p.title} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment