Leser: 22
1 2 3 4 5 6 7 8 9 10 11 12 13 14
sub _all_readable { my $not_readable = 0; for my $file ( @_ ) { $not_readable++ if !-r $file; } return !$not_readable; } if ( _all_readable( @list_of_files ) ) { # action }
if ( eval join '&', map -r, @files ) { ... }
1 2 3 4 5 6 7 8 9 10 11 12 13
sub _all_readable { for ( @_ ) { return 0 if !-r; } return 1; } if ( _all_readable( @list_of_files ) ) { # action }
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
# 1000 Dateien, Datei-Nr. 999 ist nicht lesbar:
$ perl bench.pl
Rate eval sub1 sub2 all
eval 523/s -- -60% -61% -64% # using eval and join
sub1 1318/s 152% -- -1% -9% # sub with addition
sub2 1330/s 154% 1% -- -8% # sub with direct return from loop
all 1450/s 177% 10% 9% -- # sub with usage of List::MoreUtils::all
# 2000 Dateien, Datei-Nr. 999 ist nicht lesbar:
$ perl bench.pl
Rate eval sub1 sub2 all
eval 243/s -- -61% -81% -83%
sub1 620/s 155% -- -53% -57%
sub2 1309/s 438% 111% -- -10%
all 1450/s 496% 134% 11% --
# 10 Dateien, alle lesbar
$ perl bench.pl
Rate eval sub1 sub2 all
eval 35485/s -- -68% -68% -72%
sub1 111348/s 214% -- -1% -11%
sub2 112439/s 217% 1% -- -11%
all 125754/s 254% 13% 12% --
# 10 Dateien, Datei-Nr. 7 nicht lesbar
$ perl bench.pl
Rate eval sub1 sub2 all
eval 36202/s -- -67% -78% -79%
sub1 108687/s 200% -- -33% -38%
sub2 162293/s 348% 49% -- -7%
all 174121/s 381% 60% 7% --