Thread Seltsamer Effekt beim Dateieinlesen (31 answers)
Opened by marky at 2011-09-26 11:25

GwenDragon
 2011-09-27 09:29
#152702 #152702
User since
2005-01-17
14745 Artikel
Admin1
[Homepage]
user image
Code (perl): (dl )
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);
            }
    }
);

bei einer 100 MB Textdatei mit 1_049_600 Zeilen:

Windows 7 64bit, Perl 5.12.3:
Code: (dl )
1
2
3
     s/iter  all line
all 2.40 -- -41%
line 1.42 69% --


Debian 6 64bit, Perl 5.10.1:
Code: (dl )
1
2
3
       Rate  all line
all 1.49/s -- -31%
line 2.14/s 44% --


Ubuntu 10.04 auf VirtualBox:
Code: (dl )
1
2
3
4
test@kubuntu:/tmp$ perl t.pl
s/iter all line
all 1.22 -- -37%
line 0.766 59% --


Interessant!
Last edited: 2011-09-27 09:40:01 +0200 (CEST)

View full thread Seltsamer Effekt beim Dateieinlesen