Thread best. Feld speichern (wie z.B. bei awk)
(27 answers)
Opened by Duff at 2008-03-19 11:53 renee+2008-03-19 17:28:32-- argh... da war ich mal wieder auf dem total falschen Dampfer... und das obwohl ich letztens die Einsichten des "ppi"-Autors durchgelesen habe... (Ich verstehe immer besser wieso in NRW Python(!) im Lehrplan zugelassen ist.) BTW split kennt ein Limit-Arg damit wirds unschlagbar: 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 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 use strict; $\="\n"; $,="\t"; my $str; my $idx=25; sub idx {25}; our $str_mult=10000; our $repeats; for $repeats (100,1000,10000) { bench(); } sub bench { my $str_repeats=$str_mult/$repeats; my $str=join ",",('a'..'z')x$str_repeats; print "\n\n\n--- Benchmarking with"; print "Stringlength: ",length($str); print "Repeats: ",$repeats; #- Define Codes my $codes={ 'namedArr' => sub { my @F=split /,/ , $str ; return $F[idx]; }, 'anoArr_plus' => sub { return +(split /,/, $str) [$idx]; }, 'anoArr' => sub { return @{[ split /,/, $str]} [$idx]; }, 'anoArrRef' => sub { return [ split /,/, $str ] -> [$idx]; }, 'split_lim' => sub { return (split /,/, $str, $idx+2) [$idx]; }, # 'regEx' => # sub { # no strict qw/refs/; # $str =~ m/(.*?:,){$idx}/g; # return ${$idx-1}; # }, #'tst_err' => sub {"xyz"}, }; #- Test Codes my ($ret,$retalt); while ( my ($name, $cr) = each %$codes ) { $ret=$cr->(); # meckern bei unterschiedlichen Returns if ( $retalt and $retalt ne $ret ) { print "ERROR with sub $name, returned '$ret'"; } $retalt=$ret; # print "sub $name, returned", $ret; } #- Benchmark use Benchmark qw(cmpthese); cmpthese( $repeats, $codes); } Code: (dl
)
1 --- Benchmarking with TMTOWTDYOG (there's more than one way to dig your own grave)
|