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); }