Skip to content

Instantly share code, notes, and snippets.

@kamipo
Last active May 28, 2019 14:36
Show Gist options
  • Save kamipo/e029539f2632aee9f5e711fe66fc8842 to your computer and use it in GitHub Desktop.
Save kamipo/e029539f2632aee9f5e711fe66fc8842 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 "mysql2"
gem "pg"
gem "benchmark-ips"
end
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "mysql2", database: "test", username: "root")
# ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "test")
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
10.times do |i|
User.create!(name: "user #{i}")
end
users = User.all
Benchmark.ips do |x|
x.report("users.pluck(:id)") { users.pluck(:id) }
x.report("users.pluck(:name)") { users.pluck(:name) }
x.report("users.pluck(:created_at)") { users.pluck(:created_at) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment