Skip to content

Instantly share code, notes, and snippets.

@sgrif
Created August 25, 2017 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgrif/10a98121a23c042ee04105d15a06f116 to your computer and use it in GitHub Desktop.
Save sgrif/10a98121a23c042ee04105d15a06f116 to your computer and use it in GitHub Desktop.
require "bundler"
Bundler.require
require "active_record"
require "sequel"
require "benchmark/ips"
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "activerecord_unittest")
ActiveRecord::Base.logger = Logger.new(nil)
Sequel.connect("postgres://localhost/activerecord_unittest")
ActiveRecord::Schema.define do
create_table("users", force: true) do |t|
t.string :name, :email
t.timestamps null: false
end
end
class User < ActiveRecord::Base
end
class User2 < Sequel::Model(:users)
end
attributes = {
name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
email: "foobar@email.com"
}
1000.times do
User.create!(attributes)
end
Benchmark.ips do |bm|
bm.report("AR") do
str = ""
User.all.each do |user|
str << "name: #{user.name} email: #{user.email}\n"
end
end
bm.report("Sequel") do
str = ""
User2.all.each do |user|
str << "name: #{user.name} email: #{user.email}\n"
end
end
bm.compare!
end
Warming up --------------------------------------
AR 7.000 i/100ms
Sequel 1.000 i/100ms
Calculating -------------------------------------
AR 74.140 (±12.1%) i/s - 371.000 in 5.076408s
Sequel 19.099 (±15.7%) i/s - 94.000 in 5.025350s
Comparison:
AR: 74.1 i/s
Sequel: 19.1 i/s - 3.88x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment