Skip to content

Instantly share code, notes, and snippets.

@haileys
Last active August 29, 2015 13:59
Show Gist options
  • Save haileys/10448555 to your computer and use it in GitHub Desktop.
Save haileys/10448555 to your computer and use it in GitHub Desktop.
["2.3.14.github42", "3.0.20", "3.1.12", "3.2.17", "4.0.4", "4.1.0"].each do |version|
pid = fork do
gem "activerecord", version
require "active_record"
puts "=====> ActiveRecord #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
class Foo < ActiveRecord::Base
connection.execute "CREATE TABLE foos (id INTEGER PRIMARY KEY ASC, x INTEGER)"
create :x => 123
end
foo = if ActiveRecord::VERSION::MAJOR < 4
Foo.find(:first)
else
Foo.first
end
require "benchmark/ips"
Benchmark.ips do |x|
x.report("foo.x") do
foo.x
end
x.report("Foo.find(1)") do
Foo.find(1)
end
x.report("Foo.find_by_x(123)") do
Foo.find_by_x(123)
end
end
puts
end
Process.wait(pid)
end
=====> ActiveRecord 2.3.14
Calculating -------------------------------------
foo.x 41144 i/100ms
Foo.find(1) 773 i/100ms
Foo.find_by_x(123) 615 i/100ms
-------------------------------------------------
foo.x 2409258.0 (±5.9%) i/s - 12014048 in 5.007349s
Foo.find(1) 7898.8 (±2.7%) i/s - 40196 in 5.092745s
Foo.find_by_x(123) 6470.1 (±3.3%) i/s - 32595 in 5.043230s
=====> ActiveRecord 3.0.20
Calculating -------------------------------------
foo.x 6156 i/100ms
Foo.find(1) 732 i/100ms
Foo.find_by_x(123) 646 i/100ms
-------------------------------------------------
foo.x 77686.9 (±3.2%) i/s - 393984 in 5.076762s
Foo.find(1) 7492.2 (±3.3%) i/s - 38064 in 5.086207s
Foo.find_by_x(123) 6733.8 (±3.2%) i/s - 34238 in 5.090004s
=====> ActiveRecord 3.1.12
Calculating -------------------------------------
foo.x 1946 i/100ms
Foo.find(1) 451 i/100ms
Foo.find_by_x(123) 426 i/100ms
-------------------------------------------------
foo.x 2496865.6 (±11.7%) i/s - 11421074 in 4.674240s
Foo.find(1) 6528.8 (±3.6%) i/s - 32923 in 5.049446s
Foo.find_by_x(123) 6171.4 (±4.3%) i/s - 31098 in 5.048884s
=====> ActiveRecord 3.2.17
Calculating -------------------------------------
foo.x 1927 i/100ms
Foo.find(1) 421 i/100ms
Foo.find_by_x(123) 378 i/100ms
-------------------------------------------------
foo.x 1651935.2 (±9.8%) i/s - 7771591 in 4.777711s
Foo.find(1) 6018.6 (±4.0%) i/s - 30312 in 5.044533s
Foo.find_by_x(123) 5170.5 (±4.1%) i/s - 26082 in 5.053044s
=====> ActiveRecord 4.0.4
Calculating -------------------------------------
foo.x 1967 i/100ms
Foo.find(1) 457 i/100ms
Foo.find_by_x(123) 411 i/100ms
-------------------------------------------------
foo.x 4237237.5 (±6.2%) i/s - 19009088 in 4.510749s
Foo.find(1) 6558.9 (±2.9%) i/s - 32904 in 5.021004s
Foo.find_by_x(123) 5661.9 (±3.1%) i/s - 28359 in 5.013815s
=====> ActiveRecord 4.1.0
Calculating -------------------------------------
foo.x 1973 i/100ms
Foo.find(1) 494 i/100ms
Foo.find_by_x(123) 430 i/100ms
-------------------------------------------------
foo.x 4066587.9 (±8.7%) i/s - 18214736 in 4.525936s
Foo.find(1) 7193.6 (±3.1%) i/s - 36062 in 5.018265s
Foo.find_by_x(123) 6250.0 (±3.1%) i/s - 31390 in 5.027393s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment