Skip to content

Instantly share code, notes, and snippets.

@sgrif
Created December 22, 2014 22:08
Show Gist options
  • Save sgrif/d1c498aeb802b9204ba6 to your computer and use it in GitHub Desktop.
Save sgrif/d1c498aeb802b9204ba6 to your computer and use it in GitHub Desktop.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
gem 'benchmark/ips'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
require 'benchmark/ips'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :bs
create_table :as do |t|
t.references :b, index: true, foreign_key: true
end
end
class A < ActiveRecord::Base
belongs_to :b
end
class B < ActiveRecord::Base; end
A.create!
Benchmark.ips do |bm|
bm.report do
a = A.includes(:b).find_by_id(1)
a.b
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment