Last active
May 28, 2019 14:36
-
-
Save kamipo/e029539f2632aee9f5e711fe66fc8842 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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