Mike Heins <> wrote in
news::
> On 2005-06-09, Rodrick Brown <> wrote:
>> Hello all I have a script that processes the following data I could
>> possibly speed it up
>>
>> 0107
>> 0205
>> 0304
>> 0405
>> 0105
>> 0805
>>
>> the script just converts the output to
>>
>> Jan07
>> feb05
>> mar03
>> apr05
>>
>> etc...
>>
>> Here is a sample of how i'm doing this
....
> There's no point in using a hash for this type of thing if you
> don't do a hash key lookup.
Agreed.
However, the easiest way to speed this task up by an order of magnitude
is to avoid printing. As (I think) Anno says: Print rarely, print late.
But to decide how rarely, and how late, one would have to know more.
As a simple experiment, take the following script:
#! /usr/bin/perl
use strict;
use warnings;
my @months = qw(invalid
jan feb mar apr may jun
jul aug sep oct nov dec
);
while(<DATA>) {
next unless /^(\d\d)(\d\d)$/;
print "$months[0 + $1]$2\n";
}
__END__
In the version I will use illustrate, I have 10,000 lines of data
following __END__.
I am on Windows XP Pro, perl v.5.8.6.811 (ActiveState), Acer AMD64
Laptop with 1 GB RAM:
TimeThis : Command Line : perl ttt.pl
TimeThis : Start Time : Wed Jun 08 23:46:14 2005
TimeThis : End Time : Wed Jun 08 23:46:16 2005
TimeThis : Elapsed Time : 00:00:01.578
Now, replace the script with the following:
#! /usr/bin/perl
use strict;
use warnings;
my @months = qw(invalid
jan feb mar apr may jun
jul aug sep oct nov dec
);
my $result;
while(<DATA>) {
next unless /^(\d\d)(\d\d)$/;
$result .= "$months[0 + $1]$2\n";
}
__END__
On the exact same data set, we get:
TimeThis : Command Line : perl ttt.pl
TimeThis : Start Time : Thu Jun 09 00:02:31 2005
TimeThis : End Time : Thu Jun 09 00:02:31 2005
TimeThis : Elapsed Time : 00:00:00.187
Sinan
--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html