Dear Nigel and all,

I just used 'perftools' to profile my parser, and the result is:

Total: 1570 samples
     855  54.5%  54.5%      855  54.5% garbage_collector
     338  21.5%  76.0%      338  21.5% Hash#[]=
     125   8.0%  83.9%      234  14.9% 
Parslet::Atoms::Named#produce_return_value
      36   2.3%  86.2%       36   2.3% Hash#initialize_copy
      36   2.3%  88.5%       89   5.7% 
Parslet::Atoms::CanFlatten#flatten_sequence
      21   1.3%  89.9%      715  45.5% Enumerable#each_with_index
      20   1.3%  91.1%      715  45.5% Parslet::Atoms::Context#try_with_cache
      10   0.6%  91.8%       10   0.6% Array#initialize
      10   0.6%  92.4%       30   1.9% Parslet::Atoms::Context#lookup
       9   0.6%  93.0%      715  45.5% Parslet::Atoms::Base#apply
       9   0.6%  93.6%       10   0.6% 
Parslet::Atoms::CanFlatten#flatten_repetition
       9   0.6%  94.1%      715  45.5% Parslet::Atoms::Sequence#try
       7   0.4%  94.6%        7   0.4% Array#&
       7   0.4%  95.0%      695  44.3% Array#map
       7   0.4%  95.5%       10   0.6% Parslet::Source#pos
       5   0.3%  95.8%        5   0.3% Parslet::Atoms::Base#succ
       5   0.3%  96.1%      715  45.5% Parslet::Atoms::Named#apply
       5   0.3%  96.4%       13   0.8% Parslet::Atoms::Str#try
       4   0.3%  96.7%      109   6.9% Parslet::Atoms::CanFlatten#flatten
       4   0.3%  96.9%      325  20.7% Parslet::Atoms::Context#set
       4   0.3%  97.2%        5   0.3% Parslet::Source#consume
       3   0.2%  97.4%        3   0.2% Array#[]=
       3   0.2%  97.6%        3   0.2% Array#join
       3   0.2%  97.8%       53   3.4% Enumerable#inject
       3   0.2%  98.0%        3   0.2% Kernel#hash
       3   0.2%  98.2%        3   0.2% StringScanner#pos
       2   0.1%  98.3%        2   0.1% Hash#keys
       2   0.1%  98.4%       49   3.1% Parslet::Atoms::CanFlatten#merge_fold
       2   0.1%  98.5%        2   0.1% Parslet::Atoms::Context#err_at
       2   0.1%  98.7%       51   3.2% Parslet::Atoms::Mark#try
       2   0.1%  98.8%        8   0.5% Parslet::Atoms::Re#try
       2   0.1%  98.9%      565  36.0% Parslet::Atoms::Repetition#try
       2   0.1%  99.0%        4   0.3% Parslet::Source#pos=
       2   0.1%  99.2%        2   0.1% StringScanner#match?
       1   0.1%  99.2%        1   0.1% Array#[]
       1   0.1%  99.3%       37   2.4% Hash#merge
       1   0.1%  99.4%        1   0.1% Kernel#is_a?
       1   0.1%  99.4%      566  36.1% Kernel#loop
       1   0.1%  99.5%      691  44.0% Parslet::Atoms::Alternative#try
       1   0.1%  99.6%        1   0.1% Parslet::Atoms::Base#cached?
       1   0.1%  99.6%        1   0.1% Parslet::Atoms::Context#err
       1   0.1%  99.7%      715  45.5% Parslet::Atoms::Entity#try
       1   0.1%  99.7%        2   0.1% Parslet::Atoms::Named#to_s_inner
       1   0.1%  99.8%        1   0.1% Parslet::Slice#+
       1   0.1%  99.9%        1   0.1% StringScanner#pos=
       1   0.1%  99.9%        1   0.1% StringScanner#rest_size
       1   0.1% 100.0%        1   0.1% StringScanner#scan
       0   0.0% 100.0%        1   0.1% Array#inspect
       0   0.0% 100.0%        4   0.3% BasicObject#instance_eval
       0   0.0% 100.0%        2   0.1% FortranParser#ranged
       0   0.0% 100.0%       36   2.3% Kernel#initialize_dup
       0   0.0% 100.0%        1   0.1% Parslet::Atoms::Alternative#initialize
       0   0.0% 100.0%        4   0.3% Parslet::Atoms::Base#inspect
       0   0.0% 100.0%        1   0.1% Parslet::Atoms::Base#parse
       0   0.0% 100.0%        1   0.1% Parslet::Atoms::Base#setup_and_apply
       0   0.0% 100.0%        4   0.3% Parslet::Atoms::Base#to_s
       0   0.0% 100.0%       54   3.4% Parslet::Atoms::CanFlatten#foldl
       0   0.0% 100.0%        9   0.6% 
Parslet::Atoms::CanFlatten#warn_about_duplicate_keys
       0   0.0% 100.0%        2   0.1% Parslet::Atoms::DSL#>>
       0   0.0% 100.0%        1   0.1% Parslet::Atoms::DSL#|
       0   0.0% 100.0%        4   0.3% Parslet::Atoms::Entity#parslet
       0   0.0% 100.0%       37   2.4% Parslet::Atoms::Lookahead#try
       0   0.0% 100.0%        1   0.1% Parslet::Atoms::Repetition#to_s_inner
       0   0.0% 100.0%        1   0.1% Parslet::Atoms::Sequence#>>
       0   0.0% 100.0%        3   0.2% Parslet::Atoms::Sequence#initialize
       0   0.0% 100.0%        3   0.2% Parslet::Atoms::Sequence#to_s_inner
       0   0.0% 100.0%        1   0.1% Parslet::Parser#try
       0   0.0% 100.0%        1   0.1% Parslet::Source#chars_left
       0   0.0% 100.0%        2   0.1% Parslet::Source#matches?
       0   0.0% 100.0%       17   1.1% Proc#yield

Any idea?

Cheers
Li


在 2013-7-1,上午11:53,Nigel Thorne <[email protected]> 写道:

> just google it
> 
> http://stackoverflow.com/questions/4092641/profiling-ruby-code
> 
> ---
> "No man is an island... except Philip"
> 
> 
> On Mon, Jul 1, 2013 at 1:44 PM, Li Dong <[email protected]> wrote:
> Oh! Could you tell me what is the best tool can I use to draw a table of time 
> cost? Thanks!
> 
> Cheers
> Li
> 
> 在 2013-7-1,上午11:27,Nigel Thorne <[email protected]> 写道:
> 
>> no sorry. I meant.. "Have you run your code through a profiler to find the 
>> bottlenecks?" 
>> 
>> ie. What percentage of your time is being spent on each method?
>> 
>> Cheers
>> Nigel
>> 
>> ---
>> "No man is an island... except Philip"
>> 
>> 
>> On Mon, Jul 1, 2013 at 12:59 PM, Li Dong <[email protected]> wrote:
>> Hi Nigel,
>> 
>> Yes, the timing result is already outputted by the 'rspec' command. Here is 
>> in my environment:
>> 
>> [Notice]: Test fortran code parsing
>>  ---> Parsing uses 17.100005 seconds.
>>  ---> Converting uses 1.838105 seconds.
>> 
>> Best,
>> Li
>> 
>> 在 2013-7-1,上午10:46,Nigel Thorne <[email protected]> 写道:
>> 
>>> Please can you include your profiler results. 
>>> 
>>> Cheers
>>> Nigel
>>> 
>>> ---
>>> "No man is an island... except Philip"
>>> 
>>> 
>>> On Mon, Jul 1, 2013 at 12:51 AM, Li Dong <[email protected]> wrote:
>>> Dear all,
>>> 
>>> After several hard working days, I have implemented a Fortran parser. 
>>> Although
>>> it is still incomplete, the most thing that I am worrying about is the
>>> performance. I have tried it on a Fortran code with 2000+ lines, and it took
>>> around 20 seconds on my MacBook Pro for parsing. This can not be practical. 
>>> So
>>> I should optimize the parser, but I have no idea where to start, and which
>>> parts should be heavily optimized.
>>> 
>>> The parser is located in htt ps://gist.github.com/dongli/5791976, and the 
>>> example
>>> can be run as:
>>> 
>>>     rspec rspec_fortran_parser.rb
>>> 
>>> Any idea is appreciated!
>>> Best regards,
>>> 
>>> Li
>>> 
>>> 
>> 
>> 
> 
> 

Reply via email to