Skip to content

Instantly share code, notes, and snippets.

@stereodenis
Last active August 29, 2015 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stereodenis/c55cce82f611970ca4d1 to your computer and use it in GitHub Desktop.
Save stereodenis/c55cce82f611970ca4d1 to your computer and use it in GitHub Desktop.
benchmarks
# 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