discourse/script/micro_bench.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

29 lines
563 B
Ruby

# frozen_string_literal: true
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
User.pluck(:name).first
end
b.report("pluck with limit") do
User.limit(1).pluck(:name).first
end
b.report("raw") do
conn.exec("SELECT name FROM users LIMIT 1").getvalue(0, 0)
end
end