"...it is still against my sense of economy or ecology"
Yes sure. But as i wrote:
"...less or more useful little hints"
IMHO it wasn't a bad idea to point the OP to $.
"...The test is pretty fast and has probably relatively limited impact of performance"
So let us compare:
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw ( :hireswallclock cmpthese timethese );
our $file = qq (huge.file);
our $amount = 1_000_000;
sub karl {
our ( $file, $amount );
open( my $in, "<", $file );
while (<$in>) {
next if $. <= $amount;
1;
}
close $in;
}
sub laurent {
our ( $file, $amount );
open( my $in, "<", $file );
my $useless_header_line = <$in> for 1 .. $amount;
while (<$in>) {
1;
}
close $in;
}
my $results = timethese(
10,
{
'karlgoethebier' => 'karl',
'Laurent_R' => 'laurent',
}
);
cmpthese($results);
__END__
karls-mac-mini:monks karl$ perl -e 'print qq(Lorem ipsum kizuaheli\n)
+for 1..50_000_000;' > huge.file
karl-mac-mini:monks karl$ ls -hl huge.file
-rw-r--r-- 1 karl karl 1,0G 21 Feb 17:24 huge.file
karls-mac-mini:monks karl$ wc -l huge.file
50000000 huge.file
karls-mac-mini:monks karl$ ./1117372.pl
Benchmark: timing 10 iterations of Laurent_R, karlgoethebier...
Laurent_R: 65.9521 wallclock secs (63.43 usr + 2.34 sys = 65.77 C
+PU) @ 0.15/s (n=10)
karlgoethebier: 127.837 wallclock secs (124.90 usr + 2.55 sys = 1
+27.45 CPU) @ 0.08/s (n=10)
s/iter karlgoethebier Laurent_R
karlgoethebier 12.7 -- -48%
Laurent_R 6.58 94% --
"...relatively limited impact of performance"
This is relative. It is like it is ;-)
Thanks for your reply and best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|