|< 1 2 >| | 11 Einträge, 2 Seiten |
esskar+2007-09-24 12:53:21--wie hast du denn getestet?
mich wundert, dass regexp überhaupt schneller ist als unpack.
kannst du mal deine snippets posten?
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
use strict; use warnings; use Benchmark; my $line = 'x' x 250; open my $frontend, '>>', '/dev/null' or die $!; Benchmark::cmpthese(-1, { _regex => \&_regex, _unpack2 => \&_unpack2 }); sub _regex { my $tmp_line = $line; if( length $tmp_line < 4000 ){ $tmp_line .= "\t" x 30; } else{ $tmp_line =~ s/(.{4000})/$1\t/g; } print $frontend $tmp_line; } sub _unpack2 { my $tmp_line = $line; my $len = length($tmp_line); my $pos = 0; my $tab = 30; 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"; }
esskar+2007-09-24 13:05:41--ist dir mal in den sinn gekommen, dasss
die sache verbessert?
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
use strict; use warnings; use Benchmark; my $line = 'x' x 100; open my $frontend, '>>', '/dev/null' or die $!; Benchmark::cmpthese(-1, { _regex => \&_regex, # _unpack1 => \&_unpack1, _unpack2 => \&_unpack2 }); sub _regex { my $tmp_line = $line; if( length $tmp_line < 4000 ){ $tmp_line .= "\t" x 30; } else{ $tmp_line =~ s/(.{4000})/$1\t/g; } print $frontend $tmp_line; } sub _unpack2 { my $tmp_line = $line; my $len = length($tmp_line); my $pos = 0; my $tab = 30; if( length $tmp_line < 4000 ){ $tmp_line .= "\t" x 30; } else { 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"; }
renee+2007-09-24 14:29:36--Und wie sieht das Ergebnis nach der Änderung aus?
|< 1 2 >| | 11 Einträge, 2 Seiten |