Don't know what is slowing down my program?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I am trying to match tags in an html file, roughly as follows:

     2    # Global variable.
     3    my $lines = "slurped file content here";
     5    sub rule_for_tag_a {
     7        pos($lines) = 0;
     9        while ($lines =~ m@ complex_pattern_without_any_\G_anchors
@gsix) {
    11            if(some_condition) {
    13                # pos($lines) == x at this point.
    15            # Retrace / backtrack the pos by a small enough y,
where y >= 0.
    16                pos($lines) = x - y;
    18            next;   # <--- STEPPING OVER THIS BECOMES **VERY**
    19            }
    21        adhoc_processing_for_tag_a();
    22    }
    23 }
    24 ...

There are rules for other tags 'b', 'c', 'd', etc that *very* similar
to the rule for tag 'a' (and, you can trust me on this one)... they
differ only in the

I call these rules one after the other as follows:

    25    rule_for_tag_d ();
    26    rule_for_tag_c ();
    27    rule_for_tag_b ();
    28    rule_for_tag_a ();
    29    # Everything runs very slowly now and then from this point on!
    30            ...

Now, what I'm noticing is that, after several of the tag rules (for,
let's say, tags 'd', 'c', and 'b') have run with the usual (and as
expected) very high speed, something suddenly causes the program to
slow down substantially! I have only been able narrow down the problem
to one particular statement -- the 'next;' statement on line 18:
Stepping over line 18 and arriving at line 11 takes longer than
'expected' (roughly, about 2 to 3 seconds, which is a lot compared to
other iterations)! The next 2 or 3 iterations after the slowdown run
fine before the slowdown surfaces once again. This slowdown-fine-
slowdown-fine drama continues from this point on till the end of the

Could it be that the complexity of my regex pattern and/or the nature
of the input data ($lines) is causing Perl's Garbage Collector to
suddenly kick in?

Don't know what else to try now?

Re: Don't know what is slowing down my program?

Harry wrote:
Quoted text here. Click to load it

I'm not sure if this is the case but take a look to hard drive LED. If blink
when program slow down then I know a reason. Program consumpt too many physical
memory and system must to use swap file.
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>


Re: Don't know what is slowing down my program?

In article

Quoted text here. Click to load it

Try running the program under a code profiler that can measure who's
doing what for how long. For instance, Devel::NYTProf is handy:

Good luck :)

Site Timeline