> $benchm[name][:total] += benchm.to_a[5]
> Are you using wallclock elapsed time on purpose?
Yes. But benchmark.rb gives me the following times, too:
user system total real
For example this:
"PROCEDURE"=>
{:cnt=>481,
:times=>
[ 0.015000 0.000000 0.015000 ( 0.015625)
0.016000 0.000000 0.016000 ( 0.015625)
0.109000 0.000000 0.109000 ( 0.109375)
0.063000 0.000000 0.063000 ( 0.062500)
0.031000 0.000000 0.031000 ( 0.031250)
0.047000 0.000000 0.047000 ( 0.046875)
0.015000 0.000000 0.015000 ( 0.015625)
0.047000 0.000000 0.047000 ( 0.046875)
0.016000 0.000000 0.016000 ( 0.015625)
0.031000 0.000000 0.031000 ( 0.031250)
0.000000 0.016000 0.016000 ( 0.015625)
0.016000 0.000000 0.016000 ( 0.015625)
0.062000 0.000000 0.062000 ( 0.062500)
0.016000 0.000000 0.016000 ( 0.015625)
0.016000 0.000000 0.016000 ( 0.015625)
0.015000 0.000000 0.015000 ( 0.015625)
0.016000 0.000000 0.016000 ( 0.015625)
],
:total=>0.5468747615814209},
I tried Hitimes instead of benchmark.rb. This gives much more fine grained
results:
"PROCEDURE"=>
{:cnt=>481,
:times=>
[0.0004894476811997055,
0.0008724572536453655,
1.9555558038801022e-05,
4.330159280020226e-05,
1.8158732464600946e-05,
4.162540211116217e-05,
1.8158732464600946e-05,
4.2463497455682214e-05,
1.8158732464600946e-05,
4.134603699632216e-05,
2.626032079496137e-05,
5.3079371819602774e-05,
0.00021986034537909148,
0.0002452825708295328,
3.0171432402721576e-05,
5.335873693444278e-05,
2.5701590565281343e-05,
4.888889509700255e-05,
2.5422225450441327e-05,
4.8609529982162535e-05,
2.514286033560131e-05,
4.8330164867322525e-05,
2.514286033560131e-05,
4.8330164867322525e-05,...
I found Hitimes mentioned in a presentation about "perfer":
http://eregon.me/ruby/perfer.pdf
I'll go on trying Hitimes and see if it gives me usable results.
Axel
P.S.: The code using Hitimes is this:
require 'hitimes'
$benchm = {}
class Parslet::Atoms::Entity < Parslet::Atoms::Base
alias :old_try :try
def try(source, context, consume_all)
res = nil
name = self.to_s
$benchm[name] = {:cnt=>0, :times=>[], :total=>0.0} unless $benchm[name]
duration = Hitimes::Interval.measure do
res = old_try(source, context, consume_all)
end
$benchm[name][:cnt] += 1
unless duration == 0.0 # TODO: omit?
$benchm[name][:times] << duration
$benchm[name][:total] += duration
end
res
end
end