2011-09-26T13:08:43 markydas ist ein 1&1 Server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use Benchmark qw(timethese cmpthese) ;
$results=timethese(1000, {
rpush => sub { &m11 } ,
rall => sub { &m22 } ,
});
cmpthese( $results ) ;
sub m11 {
my @ll ;
open (DATL,"< data.txt") ;while ( my $l=<DATL> ) {push ( @ll , $l ) ;}close(DATL) ;
}
sub m22 {
open (DATL,"< data.txt") ;my @ll = <DATL> ;close(DATL) ;
}
2011-09-26T15:09:51 markySpeicher sollte mehr als genug sein. Da sind nicht mal 5% belegt, während der Ausführung.
Quotegerade habe ich ein sehr seltsames Verhalten erleben dürfen und zwar beim Einlesen einer 50MB-Datei kam es zu Out Of Memory Fehler per Shell
Quotejetzt weis man als alter Hase, dass das oft auch mit Sonderzeichen
2011-09-26T17:15:07 markyhabe ich die Erfahrung, dass der Out of Memory! Fehler auch manchmal kommt, wenn SOnderzeichen im Spiel ist.
1
2
3
4
5
create file test.txt (62914560 Byte) with 776722 Lines and 81 chars per line
Run Benchmark
Rate read push read all
read push 1.22/s -- -1%
read all 1.23/s 1% --
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 45 46 47 48 49
#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); my $file='test.txt'; my $file_size=60*1024*1024; # 60MB my $iter=10; # create file { my $lines=int($file_size/81); print "create file $file ($file_size Byte) with $lines Lines and 81 chars per line\n"; open(my $fh, '>', $file) or die("$file : $!\n"); for(1..$lines) { print $fh join('',map{chr(int(rand(94))+32)}(1..80))."\n"; } close($fh); } # open only once open(my $fh, '<', $file) or die("$file : $!\n"); # loding file in OS-Filesystem-Cache: { local $/=undef; <$fh>; } print "Run Benchmark\n"; cmpthese($iter, { 'read all' => sub{ # goto file start seek($fh,0,0); my @l=<$fh>; }, 'read push' => sub{ # goto file start seek($fh,0,0); my @l; while(<$fh>) { push(@l,$_); } }, }); close($fh);
1
2
3
4
5
6
7
8
9
use file test.txt with 66060288 Byte
use existing File
preload file
Run Benchmark
Rate read all read all seek read push read push seek
read all 1.16/s -- -1% -1% -2%
read push 1.17/s 1% -- -0% -1%
read push seek 1.17/s 1% 0% -- -1%
read all seek 1.19/s 2% 1% 1% --
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); my $file='test.txt'; my $file_size=63*1024*1024; # 60MB my $iter=10; my $size=0; $size = -s $file if(-f $file); $/="\x0A"; print "use file $file with $file_size Byte\n"; # create file if($size != $file_size) { my $lines=int($file_size/81); print "create File ($lines lines and 81 chars per Line)\n"; open(my $fh, '>', $file) or die("$file : $!\n"); for(1..$lines) { print $fh join('',map{chr(int(rand(94))+32)}(1..80)).$/; } my $diff=$file_size-($lines*81); while($diff>0) { print $fh chr(int(rand(95))+32); $diff--; } close($fh); } else { print "use existing File\n"; } # loding file in OS-Filesystem-Cache: print "preload file\n"; open(my $gfh, '<', $file) or die("$file : $!\n"); { local $/=undef; <$gfh>; } print "Run Benchmark\n"; cmpthese($iter, { 'read all' => sub{ open(my $fh, '<', $file) or die("$file : $!\n"); my @l=<$fh>; close($fh); }, 'read push' => sub{ open(my $fh, '<', $file) or die("$file : $!\n"); my @l; while(<$fh>) { push(@l,$_); } close($fh); }, 'read all seek' => sub{ # goto file start seek($gfh,0,0); my @l=<$gfh>; }, 'read push seek' => sub{ # goto file start seek($gfh,0,0); my @l; while(<$gfh>) { push(@l,$_); } }, });
1
2
3
4
5
6
7
8
9
use file test.txt with 1048576 Byte
create File (12945 lines and 81 chars per Line)
preload file
Run Benchmark
Rate read all read push read push seek read all seek
read all 75.5/s -- -1% -2% -3%
read push 76.2/s 1% -- -1% -2%
read push seek 77.0/s 2% 1% -- -1%
read all seek 77.6/s 3% 2% 1% --
1
2
3
4
5
6
7
8
9
Rate read all seek read all read push read push seek
read all seek 43.3/s -- -4% -43% -43%
read all 45.0/s 4% -- -41% -41%
read push 76.0/s 76% 69% -- -1%
read push seek 76.5/s 77% 70% 1% --
1
2
3
4
5
Rate read all read all seek read push read push seek
read all 104/s -- -0% -6% -10%
read all seek 104/s 0% -- -6% -10%
read push 111/s 7% 6% -- -4%
read push seek 116/s 11% 11% 4% --
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 45 46 47 48
#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); my $file='test.txt'; my $file_size=1*1024*1024; # 1MB my $iter=1000; my $data=''; { my $lines=int($file_size/81); print "create DATA ($lines lines and 81 chars per Line)\n"; for(1..$lines) { $data.=join('',map{chr(int(rand(94))+32)}(1..80)).$/; } my $diff=$file_size-($lines*81); while($diff>0) { $data.=chr(int(rand(95))+32); $diff--; } } print "set FileHandle\n"; open(my $gfh, '<', \$data) or die("DATA : $!\n"); print "Run Benchmark\n"; cmpthese($iter, { 'read_all' => sub{ # goto start seek($gfh,0,0); my @l=<$gfh>; }, 'read_push' => sub{ # goto start seek($gfh,0,0); my @l; while(<$gfh>) { push(@l,$_); } }, });
1
2
3
4
5
6
create DATA (12945 lines and 81 chars per Line)
set FileHandle
Run Benchmark
Rate read_push read_all
read_push 80.7/s -- -2%
read_all 82.0/s 2% --
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 use strict; use warnings; use Benchmark qw/cmpthese/; my $count = 100; cmpthese( $count, { 'line' => sub { my $f1; open( $f1, "< file" ); while ( my $l = <$f1> ) { push( my @ll, $l ); } close($f1); }, 'all' => sub { my $f1; open( $f1, "< file" ); my @ll = <$f1>; close($f1); } } );