Created
February 20, 2014 14:11
-
-
Save djbender/9114435 to your computer and use it in GitHub Desktop.
AdequateRecord Pro™ (ActiveRecord) Benchmark Example lifted from @tenderlove http://tenderlovemaking.com/2014/02/19/adequaterecord-pro-like-activerecord.html
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 'active_support' | |
require 'active_record' | |
p ActiveRecord::VERSION::STRING | |
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' | |
ActiveRecord::Base.connection.instance_eval do | |
create_table(:people) { |t| t.string :name } | |
end | |
class Person < ActiveRecord::Base; end | |
person = Person.create! name: 'Aaron' | |
id = person.id | |
name = person.name | |
Benchmark.ips do |x| | |
x.report('find') { Person.find id } | |
x.report('find_by_name') { Person.find_by_name name } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment