Created
July 8, 2010 15:08
-
-
Save norman/468126 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 "rubygems" | |
require "pg" | |
require "rbench" | |
query = "SELECT * FROM people WHERE id = $1 LIMIT 1" | |
conn = PGconn.open(:dbname => "random_test") | |
stmt = conn.prepare "orm_load", query | |
RBench.run(100000) do | |
column :times | |
column :time | |
report 'Prepared statements' do | |
time { | |
id = rand 1_000_000 | |
result = conn.exec_prepared("orm_load", [id]) | |
# p result.field_values("name")[0] | |
} | |
end | |
report 'Direct SQL' do | |
time { | |
id = rand 1_000_000 | |
result = conn.exec(query, [id]) | |
# p result.field_values("name")[0] | |
} | |
end | |
end | |
# My results, using pg 0.9.0, Postgres 8.4.2, and Ruby 1.9.2-head, | |
# on a table with 2 fields and one million rows: | |
# | |
# | TIME | | |
# ----------------------------------------------- | |
# Prepared statements x100000 | 11.099 | | |
# Direct SQL x100000 | 17.639 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment