Wednesday, January 28, 2015

Benchmark scan and match

2.0.0-p598 :001 > require 'benchmark'
 => true
2.0.0-p598 :002 > url='http://www.nytimes.com/2015/01/28/opinion/a-new-chapter-for-america-and-india.html?ref=opinion&_r=0'
 => "http://www.nytimes.com/2015/01/28/opinion/a-new-chapter-for-america-and-india.html?ref=opinion&_r=0"
2.0.0-p598 :003 > Benchmark.bmbm(100) do |b|
2.0.0-p598 :004 >     b.report("scan function") do
2.0.0-p598 :005 >       title = url.scan(/\w+-[\w+-]+/).join.gsub("-"," ").capitalize
2.0.0-p598 :006?>     end
2.0.0-p598 :007?>     b.report("match function") do
2.0.0-p598 :008 >       title = url.match(/\w+-[\w+-]+/).to_s.gsub("-"," ").capitalize
2.0.0-p598 :009?>     end
2.0.0-p598 :010?>   end




Rehearsal ----------------------------------------------------------------------------------------------------------------------------------------
scan function                                                                                          0.000000   0.000000   0.000000 (  0.000113)
match function                                                                                         0.000000   0.000000   0.000000 (  0.000092)
------------------------------------------------------------------------------------------------------------------------------- total: 0.000000sec

                                                                                                           user     system      total        real
scan function                                                                                          0.000000   0.000000   0.000000 (  0.000052)
match function                                                                                         0.000000   0.000000   0.000000 (  0.000033)
 => [#<Benchmark::Tms:0x00000002083930 @label="scan function", @real=5.2013e-05, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.0, @total=0.0>, #<Benchmark::Tms:0x00000002083778 @label="match function", @real=3.2601e-05, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.0, @total=0.0>]

No comments:

Post a Comment