in reply to Re: Reducing Array Interations
in thread Reducing Array Interations

This is definately cleaner than my approach, thus why I asked the question (and why I will use it). But I ran some benchmarks on just this section of code (derived from a 260K file) and it's not any faster. This test case is much larger than most of what I would be passing through it so it's not terribly significant, but I thought your approach would be more efficient. Kind of interesting at least to me. Thanks for your assistance.

Original:
Time: 27 wallclock secs (25.88 usr + 0.00 sys = 25.88 CPU)
Time: 26 wallclock secs (25.75 usr + 0.00 sys = 25.75 CPU)
Time: 27 wallclock secs (25.73 usr + 0.00 sys = 25.73 CPU)
Time: 27 wallclock secs (25.88 usr + 0.00 sys = 25.88 CPU)
Time: 26 wallclock secs (25.75 usr + 0.00 sys = 25.75 CPU)

New:
Time: 26 wallclock secs (25.97 usr + 0.00 sys = 25.97 CPU)
Time: 26 wallclock secs (26.13 usr + 0.00 sys = 26.13 CPU)
Time: 26 wallclock secs (26.39 usr + 0.00 sys = 26.39 CPU)
Time: 27 wallclock secs (26.30 usr + 0.00 sys = 26.30 CPU)
Time: 27 wallclock secs (26.31 usr + 0.00 sys = 26.31 CPU)

-THRAK
www.polarlava.com

Replies are listed 'Best First'.
Re: Re: Re: Reducing Array Interations
by blakem (Monsignor) on Aug 17, 2001 at 02:03 UTC
    Thats probably because the joined pattern is really overkill in this situation. With the gigantic pattern, we wind up examining each row for each pattern, which requires an inordinate amount of backtracking. If you know that all your tags at the front will be similiar (like the ones in the sample data are) you wind up doing a lot more work than necessary. See if the code below runs any faster...

    my @tmp; my %text_remove = map {$_=>1} @text_remove; for (@xlate_data) { s/^(\[TEXT\-\d+\])//; $text_remove{$1} ? $tmp[-1] .= "$_" : push(@tmp,"$1$_"); } @xlate_data = @tmp;

    Here, we grab the tag off the front and compare it with a hash of the "special" tags. This should be much quicker than running a gigantic pattern against the data.

    -Blake

      Blake,

      Just a little bit...Time: 0 wallclock secs ( 0.22 usr + 0.00 sys = 0.22 CPU) ;)

      Thank you.

      -THRAK
      www.polarlava.com