Thread Anzahl Zeilen in Textdatei ermitteln: (Wie mache ich das am schnellsten?) (34 answers)
Opened by Crian at 2004-04-21 11:58

Taulmarill
 2004-04-21 14:02
#81705 #81705
User since
2004-02-19
1750 Artikel
BenutzerIn

user image
arrggg, kann ... mich nicht .... zurückhalten....
muss ... benchmarken .....

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/perl -w

use strict;
use Benchmark;

timethese(5, {
A => sub {
open ( FILE, "<test.txt" );
my $ln;
while ( <FILE> ) {
$ln++;
}
close (FILE);
},
B => sub {
open ( FILE, "<test.txt" );
my @array;
my $ln = scalar(@array = <FILE>);
close (FILE);
}
});


Code: (dl )
1
2
3
Benchmark: timing 5 iterations of A, B...
A: 24 wallclock secs (23.49 usr + 0.34 sys = 23.83 CPU) @ 0.21/s (n=5)
B: 54 wallclock secs (52.74 usr + 1.40 sys = 54.14 CPU) @ 0.09/s (n=5)


text.txt ist 20267625 Bytes gross und hat 1.200.000 Zeilen
$_=unpack"B*",~pack"H*",$_ and y&1|0& |#&&print"$_\n"for@.=qw BFA2F7C39139F45F78
0A28104594444504400 0A2F107D54447DE7800 0A2110453444450500 73CF1045138445F4800 0
F3EF2044E3D17DE 8A08A0451412411 F3CF207DF41C79E 820A20451412414 83E93C4513D17D2B

View full thread Anzahl Zeilen in Textdatei ermitteln: (Wie mache ich das am schnellsten?)