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