Thank you for the advice, Kaspar. That's the entry point I was looking
for, I didn't find it on my own.
I had only very few time to work on this, hence I made only small
progress. I used benchmark.rb to wrap #try in 'parslet/atoms/entity'. But
the result was quite unexpected:
* A lot of 0-times (I believe, I understand this; probably due to rejected
"trys")
* All other times are multiples of ~15 ms (~15 ms, ~31 ms, ~46 ms, ...),
nothing like 3 ms, for example. I don't understand this. In my eyes, this
makes the result suspicious.
Next, I want to try "perfer". Hopefully it will give me reliable results.
Some details follow.
The code I used:
require 'benchmark'
$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]
benchm = Benchmark.measure {
res = old_try(source, context, consume_all)
}
$benchm[name][:cnt] += 1
unless benchm.to_a[5] == 0.0
$benchm[name][:times] << benchm
$benchm[name][:total] += benchm.to_a[5]
end
res
end
end
...
pp $benchm
My machine:
* Mobile AMD Sempron 3500+,1.79 GHz (several years old, single core)
* Windows XP home
* antivirus on/off makes no noticeable difference
Kind regards,
Axel
On Mon, 22 Jul 2013 15:55:13 +0200, Kaspar Schiess
<[email protected]> wrote:
>> I want to evaluate which rule consumes how much time and then optimize
>> the
>> most time consuming rules.
>
> Good idea. Have a look at 'parslet/atoms/entity' - hooking the #try
> method should allow you to do that.