From c6bbc10faea55df72000a82a2f6767278a76f121 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 17 Aug 2012 13:52:16 +0100 Subject: [PATCH] Increase benchmark time to 20 seconds. I think that 5 seconds was a bit low for our purposes. Also enable it to be configured via env vars. We also need to scale the number of records up/down depending on how long we're running the benchmark for. --- activerecord/examples/performance.rb | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/activerecord/examples/performance.rb b/activerecord/examples/performance.rb index 55679b644c7ce..cd9825b50c8a4 100644 --- a/activerecord/examples/performance.rb +++ b/activerecord/examples/performance.rb @@ -2,6 +2,9 @@ require "active_record" require 'benchmark/ips' +TIME = (ENV['BENCHMARK_TIME'] || 20).to_i +RECORDS = (ENV['BENCHMARK_RECORDS'] || TIME*1000).to_i + conn = { :adapter => 'sqlite3', :database => ':memory:' } ActiveRecord::Base.establish_connection(conn) @@ -71,8 +74,8 @@ def self.email notes = ActiveRecord::Faker::LOREM.join ' ' today = Date.today -puts 'Inserting 10,000 users and exhibits...' -10_000.times do +puts "Inserting #{RECORDS} users and exhibits..." +RECORDS.times do user = User.create( :created_at => today, :name => ActiveRecord::Faker.name, @@ -87,22 +90,7 @@ def self.email ) end -# These ones need more than 5 secs in order to get a useful result -Benchmark.ips(20) do |x| - x.report("Model.all limit(100)") do - Exhibit.look Exhibit.limit(100) - end - - x.report "Model.all limit(100) with relationship" do - Exhibit.feel Exhibit.limit(100).includes(:user) - end - - x.report "Model.all limit(10,000)" do - Exhibit.look Exhibit.limit(10000) - end -end - -Benchmark.ips do |x| +Benchmark.ips(TIME) do |x| ar_obj = Exhibit.find(1) attrs = { :name => 'sam' } attrs_first = { :name => 'sam' } @@ -129,6 +117,18 @@ def self.email Exhibit.first.look end + x.report("Model.all limit(100)") do + Exhibit.look Exhibit.limit(100) + end + + x.report "Model.all limit(100) with relationship" do + Exhibit.feel Exhibit.limit(100).includes(:user) + end + + x.report "Model.all limit(10,000)" do + Exhibit.look Exhibit.limit(10000) + end + x.report 'Model.named_scope' do Exhibit.limit(10).with_name.with_notes end