Last active
August 29, 2015 14:09
-
-
Save larskanis/aec0a74cb3454f696b08 to your computer and use it in GitHub Desktop.
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 'active_support' | |
require 'active_record' | |
require 'benchmark/ips' | |
p ActiveRecord::VERSION::STRING | |
# ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' | |
ActiveRecord::Base.establish_connection adapter: 'postgresql' | |
ActiveRecord::Base.connection.instance_eval do | |
create_table(:people, force: true) do |t| | |
t.string :name | |
t.integer :fingers | |
t.integer :group_id | |
t.float :height | |
t.boolean :committer | |
t.timestamps | |
end | |
end | |
class Person < ActiveRecord::Base; end | |
person = Person.create! name: 'Aaron', fingers: 10, group_id: 123, height: 1.9, committer: true | |
id = person.id | |
name = person.name | |
pgconn = Person.connection.raw_connection | |
pgconn.prepare("test1", "select * from people where id=$1") | |
Benchmark.ips do |x| | |
x.report('find') { Person.find(id).fingers } | |
x.report('find_by_name') { Person.find_by_name(name).fingers } | |
x.report('raw conn') { pgconn.exec_params("select * from people where id=$1", [id]).values } | |
x.report('raw prepared') { pgconn.exec_prepared("test1", [id]).values } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment