![]() |
|< 1 2 3 4 >| | ![]() |
35 entries, 4 pages |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl -w
use strict;
$| = 1;
my $file = "test.txt";
my $maxsize = -s $file;
my $accsize = "0";
my $accperc = "0.0125";
print " 10%| 20%| 30%| 40%| 50%| 60%| 70%| 80%| 90%| 100%|\n";
open ( F, "<$file" ) or die $!;
while (<F>) {
$accsize += length $_;
if ( $accsize / $maxsize >= $accperc ) {
print "#";
$accperc += 0.0125;
}
# inserd your code here
}
print "\n";
1
2
3
4
5
6
7
C:\Daten\perl>benchmark.pl
Benchmark: timing 100 iterations of A, A2, C, D...
A: 307 wallclock secs (272.94 usr + 27.55 sys = 300.49 CPU) @ 0.33/s (n=100)
A2: 316 wallclock secs (278.64 usr + 24.92 sys = 303.56 CPU) @ 0.33/s (n=100)
C: 333 wallclock secs (278.80 usr + 23.83 sys = 302.63 CPU) @ 0.33/s (n=100)
D: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)
(warning: too few iterations for a reliable count)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
my $file = 'test.txt';
timethese(100, {
A => sub {
open ( FILE, $file );
my $ln;
$ln++ while <FILE>;
close (FILE);
},
A2 => sub {
my $ln;
open ( FILE, $file );
++$ln while <FILE>;
close (FILE);
},
# ist unter C ein Unterschied, spart temporäre Variable...
#B => sub {
# open ( FILE, $file );
# my @array;
# my $ln = scalar(@array = <FILE>);
# close (FILE);
# },
C => sub {
open ( FILE, $file );
while ( <FILE> ) {}
my $ln = $.;
close (FILE);
},
D => sub {
my $ln = -s $file;
},
}
);
# test.txt hat 3.804.144 Zeilen und ist 195.338.421 Byte groß
![]() |
|< 1 2 3 4 >| | ![]() |
35 entries, 4 pages |