Skip to content

Commit

Permalink
Increase benchmark time to 20 seconds.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonleighton committed Aug 17, 2012
1 parent 1411fc1 commit c6bbc10
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions activerecord/examples/performance.rb
Expand Up @@ -2,6 +2,9 @@
require "active_record" require "active_record"
require 'benchmark/ips' require 'benchmark/ips'


TIME = (ENV['BENCHMARK_TIME'] || 20).to_i
RECORDS = (ENV['BENCHMARK_RECORDS'] || TIME*1000).to_i

conn = { :adapter => 'sqlite3', :database => ':memory:' } conn = { :adapter => 'sqlite3', :database => ':memory:' }


ActiveRecord::Base.establish_connection(conn) ActiveRecord::Base.establish_connection(conn)
Expand Down Expand Up @@ -71,8 +74,8 @@ def self.email
notes = ActiveRecord::Faker::LOREM.join ' ' notes = ActiveRecord::Faker::LOREM.join ' '
today = Date.today today = Date.today


puts 'Inserting 10,000 users and exhibits...' puts "Inserting #{RECORDS} users and exhibits..."
10_000.times do RECORDS.times do
user = User.create( user = User.create(
:created_at => today, :created_at => today,
:name => ActiveRecord::Faker.name, :name => ActiveRecord::Faker.name,
Expand All @@ -87,22 +90,7 @@ def self.email
) )
end end


# These ones need more than 5 secs in order to get a useful result Benchmark.ips(TIME) do |x|
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|
ar_obj = Exhibit.find(1) ar_obj = Exhibit.find(1)
attrs = { :name => 'sam' } attrs = { :name => 'sam' }
attrs_first = { :name => 'sam' } attrs_first = { :name => 'sam' }
Expand All @@ -129,6 +117,18 @@ def self.email
Exhibit.first.look Exhibit.first.look
end 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 x.report 'Model.named_scope' do
Exhibit.limit(10).with_name.with_notes Exhibit.limit(10).with_name.with_notes
end end
Expand Down

0 comments on commit c6bbc10

Please sign in to comment.