यहां एक तकनीक है जो काम करती है, सुनिश्चित नहीं है कि यह सबसे अच्छा है या नहीं।
require 'sinatra'
require 'profiler'
get '/' do
Profiler__.start_profile
do_it_fast
do_it_slow
do_it_fast
Profiler__.stop_profile
Profiler__.print_profile(STDOUT)
"done"
end
def do_it_fast
1.upto(100){ Math.sqrt(rand) }
end
def do_it_slow
1.upto(100_000){ (Math.sqrt(rand)).ceil }
end
#=> In the console:
#=> % cumulative self self total
#=> time seconds seconds calls ms/call ms/call name
#=> 68.45 2.82 2.82 3 940.00 1373.33 Integer#upto
#=> 11.41 3.29 0.47 100200 0.00 0.00 Kernel.rand
#=> 10.92 3.74 0.45 100000 0.00 0.00 Float#ceil
#=> 9.22 4.12 0.38 100200 0.00 0.00 Math.sqrt
#=> 0.00 4.12 0.00 2 0.00 5.00 Object#do_it_fast
#=> 0.00 4.12 0.00 1 0.00 4110.00 Object#do_it_slow
#=> 0.00 4.12 0.00 1 0.00 4120.00 #toplevel
पर "perftools.rb" के लिए
खोजें मैं आम तौर पर एक मार्ग के भीतर सभी तरीकों में से मैनुअल उपकरण प्रदर्शन करते हैं। यह एक अच्छा जवाब नहीं है, हालांकि, मैं इसे सिर्फ एक टिप्पणी के रूप में छोड़ दूंगा। मुझे आश्चर्य है कि बिल्ट-इन 'प्रोफाइल' लाइब्रेरी में स्नैपशॉट की रिपोर्ट करने के लिए एक तंत्र है। – Phrogz