Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created September 28, 2012 17:55
Show Gist options
  • Select an option

  • Save jonleighton/3801265 to your computer and use it in GitHub Desktop.

Select an option

Save jonleighton/3801265 to your computer and use it in GitHub Desktop.
require 'active_record'
require 'benchmark/ips'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
class Post < ActiveRecord::Base
connection.create_table :posts do |t|
t.string :name
end
end
p = Post.create! name: 'omg'
Benchmark.ips do |r|
r.report('access') { p.name }
end
Calculating -------------------------------------
access 6534 i/100ms
-------------------------------------------------
access 420970.0 (±21.1%) i/s - 1927530 in 4.987156s
Calculating -------------------------------------
access 8583 i/100ms
-------------------------------------------------
access 1540592.1 (±1.1%) i/s - 7681785 in 4.987032s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment