Skip to content

Instantly share code, notes, and snippets.

@kamipo
Last active May 28, 2019 14:37
Show Gist options
  • Save kamipo/11d428b57f3629a72ae89c6f21721326 to your computer and use it in GitHub Desktop.
Save kamipo/11d428b57f3629a72ae89c6f21721326 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "sqlite3"
gem "benchmark-ips"
end
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name
t.timestamps null: false
end
end
class User < ActiveRecord::Base
end
users = User.all
Benchmark.ips do |x|
x.report("users.pluck(:id)") { users.pluck(:id) }
x.report("users.order(:id).to_sql") { users.order(:id).to_sql }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment