2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-12-03 16:30:44 -06:00
|
|
|
require 'benchmark/ips'
|
|
|
|
require File.expand_path("../../config/environment", __FILE__)
|
|
|
|
|
|
|
|
conn = ActiveRecord::Base.connection.raw_connection
|
|
|
|
|
|
|
|
Benchmark.ips do |b|
|
|
|
|
b.report("simple") do
|
|
|
|
User.first.name
|
|
|
|
end
|
|
|
|
|
|
|
|
b.report("simple with select") do
|
|
|
|
User.select("name").first.name
|
|
|
|
end
|
|
|
|
|
|
|
|
b.report("pluck with first") do
|
2019-10-21 06:21:10 -05:00
|
|
|
User.pluck(:name).first
|
2014-12-03 16:30:44 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
b.report("pluck with limit") do
|
2019-10-21 06:21:10 -05:00
|
|
|
User.limit(1).pluck(:name).first
|
|
|
|
end
|
|
|
|
|
|
|
|
b.report("pluck with pluck_first") do
|
2019-10-21 05:32:27 -05:00
|
|
|
User.pluck_first(:name)
|
2014-12-03 16:30:44 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
b.report("raw") do
|
2017-07-27 20:20:09 -05:00
|
|
|
conn.exec("SELECT name FROM users LIMIT 1").getvalue(0, 0)
|
2014-12-03 16:30:44 -06:00
|
|
|
end
|
|
|
|
end
|