discourse/script/micro_bench.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
584 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-12-04 06:30:44 +08:00
require "benchmark/ips"
require File.expand_path("../../config/environment", __FILE__)
conn = ActiveRecord::Base.connection.raw_connection
Benchmark.ips do |b|
b.report("simple") { User.first.name }
b.report("simple with select") { User.select("name").first.name }
b.report("pluck with first") { User.pluck(:name).first }
b.report("pluck with limit") { User.limit(1).pluck(:name).first }
b.report("pluck with pluck_first") { User.pluck_first(:name) }
2014-12-04 06:30:44 +08:00
b.report("raw") { conn.exec("SELECT name FROM users LIMIT 1").getvalue(0, 0) }
end