mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
micro bench template
This commit is contained in:
parent
d1cb946594
commit
6d1321192a
1 changed files with 27 additions and 0 deletions
27
script/micro_bench.rb
Normal file
27
script/micro_bench.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue