Skip to content

Instantly share code, notes, and snippets.

@jeremyevans
Forked from tenderlove/test.rb
Created April 27, 2012 18:13
Show Gist options
  • Save jeremyevans/2511463 to your computer and use it in GitHub Desktop.
Save jeremyevans/2511463 to your computer and use it in GitHub Desktop.
Calculating -------------------------------------
AR new 1110 i/100ms
AR new args 479 i/100ms
AR create 57 i/100ms
AR find 131 i/100ms
-------------------------------------------------
AR new 13570.5 (±5.4%) i/s - 67710 in 5.003359s
AR new args 5271.7 (±6.5%) i/s - 26345 in 5.018283s
AR create 576.4 (±6.2%) i/s - 2907 in 5.062781s
AR find 1357.2 (±4.2%) i/s - 6812 in 5.027665s
Calculating -------------------------------------
S new 4709 i/100ms
S new args 1535 i/100ms
S create 56 i/100ms
S find 184 i/100ms
-------------------------------------------------
S new 238525.9 (±20.2%) i/s - 1125451 in 5.003512s
S new args 20624.3 (±9.8%) i/s - 102845 in 5.047348s
S create 568.3 (±10.4%) i/s - 2800 in 4.997816s
S find 1901.8 (±11.6%) i/s - 9384 in 5.016500s
require 'active_record'
require 'benchmark/ips'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:')
ActiveRecord::Base.connection.create_table('posts') do |t|
t.string :name
t.timestamps
end
class Post < ActiveRecord::Base
end
post = Post.create(:name => 'aaron')
id = post.id
Benchmark.ips do |x|
x.report("AR new") { Post.new }
x.report("AR new args") { Post.new(:name => 'aaron') }
x.report("AR create") { Post.create(:name => 'aaron') }
x.report("AR find") { Post.find(id) }
end
require 'sequel'
Sequel.sqlite.create_table(:sposts) do |t|
primary_key :id
String :name
Time :created_at, :default=>Sequel::CURRENT_TIMESTAMP
Time :updated_at
end
id = class Spost < Sequel::Model
plugin :prepared_statements
def before_update
self.updated_at = Time.now
super
end
insert(:name => 'aaron')
end
Benchmark.ips do |x|
x.report("S new") { Spost.new }
x.report("S new args") { Spost.new(:name => 'aaron') }
x.report("S create") { Spost.create(:name => 'aaron') }
x.report("S find") { Spost[id] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment