Skip to content

Instantly share code, notes, and snippets.

@bogdan
Created October 29, 2018 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdan/31fbdf0cfe12bf55e07e275650d45c4f to your computer and use it in GitHub Desktop.
Save bogdan/31fbdf0cfe12bf55e07e275650d45c4f to your computer and use it in GitHub Desktop.
require "benchmark/ips"
quiet_logger
c = ActiveRecord::Base.connection
mysql = c.instance_variable_get("@connection")
sql = "select * from users where id = 1"
Benchmark.ips do |x|
x.time = 5
x.warmup = 0.1
x.report("ActiveRecord::Base") do
User.find(1)
end
x.report("Connection query") do
c.execute(sql)
end
x.report("No ActiveRecord") do
mysql.query(sql)
end
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment