|< 1 2 3 >| | 30 Einträge, 3 Seiten |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
if($logFile =~ /^dn/ ) { $laenge = length($tmp_line); if($laenge <=4000) { print $frontend "$tmp_line\t\t\t\t\n"; } elsif($laenge <= 8000) { my ($a, $b) = unpack("A4000 A4000", $tmp_line); print $frontend "$a\t$b\t\t\t\n"; } elsif($laenge <= 12000) { my ($a, $b, $c) = unpack("A4000 A4000 A4000", $tmp_line); print $frontend "$a\t$b\t$c\t\t\n"; } elsif($laenge <= 16000) { my ($a, $b, $c, $d) = unpack("A4000 A4000 A4000 A4000", $tmp_line); print $frontend "$a\t$b\t$c\t$d\t\n"; } }
1 2 3 4 5 6
if( length $tmp_line < 4000 ){ $tmp_line .= "\t" x 5; } else{ $tmp_line =~ s/(.{4000})/$1\t/g; }
1 2 3 4 5 6 7 8 9 10 11
my $len = length($tmp_line); my $pos = 0; my $tab = 5; while ( my $s = unpack("x$pos A4000", $tmp_line) ) { $tab--; print $frontend "$s\t"; $pos += 4000; last if $pos >= $len; } print $frontend "\t" x $tab; print $frontend "\n";
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
use strict; use warnings; use Benchmark; my $tmp_line = 'x' x 18_000; open my $frontend, '>>', '/dev/null' or die $!; Benchmark::cmpthese(-1, { _regex => \&_regex, _unpack1 => \&_unpack1, _unpack2 => \&_unpack2 }); sub _regex { if( length $tmp_line < 4000 ){ $tmp_line .= "\t" x 5; } else{ $tmp_line =~ s/(.{4000})/$1\t/g; } print $frontend $tmp_line; } sub _unpack1 { my $laenge = length($tmp_line); if($laenge <=4000) { print $frontend "$tmp_line\t\t\t\t\n"; } elsif($laenge <= 8000) { my ($a, $b) = unpack("A4000 A4000", $tmp_line); print $frontend "$a\t$b\t\t\t\n"; } elsif($laenge <= 12000) { my ($a, $b, $c) = unpack("A4000 A4000 A4000", $tmp_line); print $frontend "$a\t$b\t$c\t\t\n"; } elsif($laenge <= 16000) { my ($a, $b, $c, $d) = unpack("A4000 A4000 A4000 A4000", $tmp_line); print $frontend "$a\t$b\t$c\t$d\t\n"; } } sub _unpack2 { my $len = length($tmp_line); my $pos = 0; my $tab = 5; while ( my $s = unpack("x$pos A4000", $tmp_line) ) { $tab--; print $frontend "$s\t"; $pos += 4000; last if $pos >= $len; } print $frontend "\t" x $tab; print $frontend "\n"; }
1
2
3
4
Rate _regex _unpack2 _unpack1
_regex 1172/s -- -98% -100%
_unpack2 48188/s 4012% -- -97%
_unpack1 1557667/s 132813% 3133% --
1
2
3
4
Rate _regex _unpack2 _unpack1
_regex 1840/s -- -92% -100%
_unpack2 23659/s 1186% -- -99%
_unpack1 2044729/s 111046% 8542% --
Benchmark::cmpthese(100_000_000 ...
|< 1 2 3 >| | 30 Einträge, 3 Seiten |