Merge pull request #11336 from ankit8898/performance-bm
Some performance benchmarking for take vs limit
This commit is contained in:
commit
8f25e08dda
@ -43,6 +43,8 @@ def self.look(exhibits) exhibits.each { |e| e.look } end
|
|||||||
def self.feel(exhibits) exhibits.each { |e| e.feel } end
|
def self.feel(exhibits) exhibits.each { |e| e.feel } end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def progress_bar(int); print "." if (int%100).zero? ; end
|
||||||
|
|
||||||
puts 'Generating data...'
|
puts 'Generating data...'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
@ -75,7 +77,7 @@ def self.email
|
|||||||
today = Date.today
|
today = Date.today
|
||||||
|
|
||||||
puts "Inserting #{RECORDS} users and exhibits..."
|
puts "Inserting #{RECORDS} users and exhibits..."
|
||||||
RECORDS.times do
|
RECORDS.times do |record|
|
||||||
user = User.create(
|
user = User.create(
|
||||||
created_at: today,
|
created_at: today,
|
||||||
name: ActiveRecord::Faker.name,
|
name: ActiveRecord::Faker.name,
|
||||||
@ -88,7 +90,9 @@ def self.email
|
|||||||
user: user,
|
user: user,
|
||||||
notes: notes
|
notes: notes
|
||||||
)
|
)
|
||||||
|
progress_bar(record)
|
||||||
end
|
end
|
||||||
|
puts "Done!\n"
|
||||||
|
|
||||||
Benchmark.ips(TIME) do |x|
|
Benchmark.ips(TIME) do |x|
|
||||||
ar_obj = Exhibit.find(1)
|
ar_obj = Exhibit.find(1)
|
||||||
@ -117,10 +121,18 @@ def self.email
|
|||||||
Exhibit.first.look
|
Exhibit.first.look
|
||||||
end
|
end
|
||||||
|
|
||||||
|
x.report 'Model.take' do
|
||||||
|
Exhibit.take
|
||||||
|
end
|
||||||
|
|
||||||
x.report("Model.all limit(100)") do
|
x.report("Model.all limit(100)") do
|
||||||
Exhibit.look Exhibit.limit(100)
|
Exhibit.look Exhibit.limit(100)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
x.report("Model.all take(100)") do
|
||||||
|
Exhibit.look Exhibit.take(100)
|
||||||
|
end
|
||||||
|
|
||||||
x.report "Model.all limit(100) with relationship" do
|
x.report "Model.all limit(100) with relationship" do
|
||||||
Exhibit.feel Exhibit.limit(100).includes(:user)
|
Exhibit.feel Exhibit.limit(100).includes(:user)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user