aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/examples
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-08-17 13:52:16 +0100
committerJon Leighton <j@jonathanleighton.com>2012-08-17 15:09:01 +0100
commitc6bbc10faea55df72000a82a2f6767278a76f121 (patch)
treee44a0acf05cf2a363ddb84f28931481d3fa09802 /activerecord/examples
parent1411fc19862060a959f99be19770fb7eb1ad104f (diff)
downloadrails-c6bbc10faea55df72000a82a2f6767278a76f121.tar.gz
rails-c6bbc10faea55df72000a82a2f6767278a76f121.tar.bz2
rails-c6bbc10faea55df72000a82a2f6767278a76f121.zip
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.
Diffstat (limited to 'activerecord/examples')
-rw-r--r--activerecord/examples/performance.rb36
1 files changed, 18 insertions, 18 deletions
diff --git a/activerecord/examples/performance.rb b/activerecord/examples/performance.rb
index 55679b644c..cd9825b50c 100644
--- a/activerecord/examples/performance.rb
+++ b/activerecord/examples/performance.rb
@@ -2,6 +2,9 @@ require File.expand_path('../../../load_paths', __FILE__)
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 @@ end
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 @@ puts 'Inserting 10,000 users and exhibits...'
)
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 @@ Benchmark.ips do |x|
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