mucking with my measure script

This commit is contained in:
Sam 2013-08-29 15:27:33 +10:00
parent aaf41d227f
commit 47c6ba2f51

View file

@ -60,12 +60,49 @@ def profile(name, &block)
end end
# User.limit(10).to_a
def stuff
u = User.first
r = TopicQuery.new(u, {}).list_latest
r.topics.to_a
end
stuff
profile_allocations "stuff" do
stuff
end
# Benchmark.bmbm do |x|
#
# x.report("find") do
# 100.times{stuff}
# end
#
# end
#
# x.report("grab 10 users id") do
# 100.times{User.limit(10).select(:id).to_a}
# end
#
# x.report("grab 10 users") do
# 100.times{User.limit(10).to_a}
# end
#
# profile("topic query") do
# r = TopicQuery.new(u, {}).list_latest
# r.topics.to_a
# end
#
# RubyProf.start # RubyProf.start
# User.limit(10).to_a #
# r = TopicQuery.new(u, {}).list_latest
# r.topics.to_a
#
# result = RubyProf.stop # result = RubyProf.stop
# # printer = RubyProf::GraphPrinter.new(result) # printer = RubyProf::GraphPrinter.new(result)
# printer = RubyProf::FlatPrinter.new(result) # # printer = RubyProf::FlatPrinter.new(result)
# printer.print(STDOUT, :min_percent => 2) # printer.print(STDOUT, :min_percent => 2)
# #
# exit # exit
@ -81,40 +118,40 @@ end
# User.limit(10).to_a # User.limit(10).to_a
# exit # exit
# #
User.select('id, 2 bob').first # User.select('id, 2 bob').first
Benchmark.bmbm do |x| # Benchmark.bmbm do |x|
#
x.report("find") do # x.report("find") do
100.times{User.find(1)} # 100.times{User.find(1)}
end # end
#
x.report("grab 10 users created_at") do # x.report("grab 10 users created_at") do
100.times{User.limit(10).select(:created_at).to_a} # 100.times{User.limit(10).select(:created_at).to_a}
end # end
#
x.report("grab 10 users id") do # x.report("grab 10 users id") do
100.times{User.limit(10).select(:id).to_a} # 100.times{User.limit(10).select(:id).to_a}
end # end
#
x.report("grab 10 users") do # x.report("grab 10 users") do
100.times{User.limit(10).to_a} # 100.times{User.limit(10).to_a}
end # end
#
#
x.report("pg direct grab 10 users") do # x.report("pg direct grab 10 users") do
100.times do # 100.times do
r = ActiveRecord::Base.connection.raw_connection.async_exec("select * from users limit 10") # r = ActiveRecord::Base.connection.raw_connection.async_exec("select * from users limit 10")
r.fields.each_with_index do |f,i| # r.fields.each_with_index do |f,i|
r.ftype(i) # r.ftype(i)
end # end
r.each_row do |x| # r.each_row do |x|
x # x
end # end
end # end
end # end
#
end # end
#
# profile("find") do # profile("find") do
# User.find(1) # User.find(1)