aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-07-06 16:01:43 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-07-06 16:01:43 -0700
commit8f25e08ddafc3aea66575295ccbb32b733e41d1f (patch)
treeb5e475c70427e6ade2b710b0af7fab303b9da466 /activerecord
parentef8f49edf3d4613fafff11695da2355e6332b41e (diff)
parenta7ff577383dcf1b36d075b70713f614c598b2430 (diff)
downloadrails-8f25e08ddafc3aea66575295ccbb32b733e41d1f.tar.gz
rails-8f25e08ddafc3aea66575295ccbb32b733e41d1f.tar.bz2
rails-8f25e08ddafc3aea66575295ccbb32b733e41d1f.zip
Merge pull request #11336 from ankit8898/performance-bm
Some performance benchmarking for take vs limit
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/examples/performance.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/examples/performance.rb b/activerecord/examples/performance.rb
index 35f13d2438..d3546ce948 100644
--- a/activerecord/examples/performance.rb
+++ b/activerecord/examples/performance.rb
@@ -43,6 +43,8 @@ class Exhibit < ActiveRecord::Base
def self.feel(exhibits) exhibits.each { |e| e.feel } end
end
+def progress_bar(int); print "." if (int%100).zero? ; end
+
puts 'Generating data...'
module ActiveRecord
@@ -75,7 +77,7 @@ notes = ActiveRecord::Faker::LOREM.join ' '
today = Date.today
puts "Inserting #{RECORDS} users and exhibits..."
-RECORDS.times do
+RECORDS.times do |record|
user = User.create(
created_at: today,
name: ActiveRecord::Faker.name,
@@ -88,7 +90,9 @@ RECORDS.times do
user: user,
notes: notes
)
+ progress_bar(record)
end
+puts "Done!\n"
Benchmark.ips(TIME) do |x|
ar_obj = Exhibit.find(1)
@@ -117,10 +121,18 @@ Benchmark.ips(TIME) do |x|
Exhibit.first.look
end
+ x.report 'Model.take' do
+ Exhibit.take
+ end
+
x.report("Model.all limit(100)") do
Exhibit.look Exhibit.limit(100)
end
+ x.report("Model.all take(100)") do
+ Exhibit.look Exhibit.take(100)
+ end
+
x.report "Model.all limit(100) with relationship" do
Exhibit.feel Exhibit.limit(100).includes(:user)
end