Permalink
Browse files

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.

Conflicts:
	activerecord/examples/performance.rb
  • Loading branch information...
1 parent 20d6f70 commit e08268ba5aff0f07d875ca161420e98cfec0734c @jonleighton jonleighton committed Aug 17, 2012
Showing with 18 additions and 18 deletions.
  1. +18 −18 activerecord/examples/performance.rb
View
36 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)
@@ -56,8 +59,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,
@@ -72,22 +75,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' }
@@ -114,6 +102,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.create' do
Exhibit.create(exhibit)
end

0 comments on commit e08268b

Please sign in to comment.