#! perl -slw
use strict;
use Time::HiRes qw[ time ];
use Tie::File;
use Digest::MD5 qw[ md5_hex ];
our $N //= 1e6;
my $start = time;
open OUT, '+>:raw', 'junk.dat';
print OUT md5_hex( 0 );
my $data = 'x' x 50;
my $md5 = new Digest::MD5;
for ( 1.. $N ) {
print OUT $data;
$md5->add( "$data\n" );
}
seek OUT, 0, 0;
print OUT $md5->hexdigest;
close OUT;
printf "Took %.3f seconds\n", time-$start;
$start = time;
tie my @lines, 'Tie::File', 'junk2.dat', memory => 52 * $N;
$md5 = new Digest::MD5;
push @lines, md5_hex( 0 );
for ( 1.. $N ) {
push @lines, $data;
$md5->add( "$data\n" );
}
$lines[ 0 ] = $md5->hexdigest;
untie @lines;
printf "Took %.3f seconds\n", time-$start;
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |