in reply to advice on improving performance of this code

Hi again ;-)

In the first block I'd replace

$record->[1] = join ("_", $Map{$record->[1]}[1], $Map{$record->[1]}[0] +);
with
$record->[1] = $Map{$record->[1]}[1] . '_' . $Map{$record->[1]}[1];

In the second block I'd avoid the iteration by using join:

print DATA join(" ", @$record[0..4]), "\n";
rather than
for my $i (0 .. 4) { print DATA $record->[$i] . " "; } print DATA "\n";
or even
print DATA join(" ", @$_[0..4]), "\n" for (@Data);
that does the whole block in one line.

You can find the code I used to do the benchmarks on my scrachpad.

Hope this helps, -gjb-

Replies are listed 'Best First'.
Re: Re: advice on improving performance of this code
by tachyon (Chancellor) on Jan 03, 2003 at 23:09 UTC

    Update

    Upon testing $, tests 25% faster that join in the best case to 50% SLOWER in many cases! Presumably it relates to being faster to pass one argument to print (after the join) rather than many. Suprised me. Credit gjb for this pickup. I will be using join in future

    You can set $, to ' ' and ditch the join as well which will be faster again. Manipulating $, and $" can often useful in controlling output. local ensures no suprises elsewhere in the code.

    { local $, = ' '; print @{$_}[0..4], "\n" for @Data; }

    Note that setting $, and doing it in one line like this has the side effect of adding a ' ' after the last element and before the "\n". This can be rectified with a separate call to print for the "\n" if required. print() is actually quite slow so it may be faster to do this:

    { local $, = ' '; print @$_[0..3], $$_[4] ."\n" for @Data; }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: advice on improving performance of this code
by The_Rev (Acolyte) on Jan 04, 2003 at 02:14 UTC
    I appreciate all the advice, and especially found gjb's suggestions helpful.

    I took a look at your scratchpad, and noticed a significant improvement over my old code.

    Thanks again!