Есть такой вот код:
use strict;
use Benchmark;
use 5.010;
use warnings;
sub AUTOLOAD {
1;
}
my @func = qw/func1 func2 func3 funcN/;
sub regex {
given($_[0]){
when(m/^func1/io) { func1() }
when(m/^func2/io) { func2() }
when(m/^func3/io) { func3() }
when(m/^funcN/io) { funcN() }
}
}
sub eval_f {
eval(join('',lc($_[0]),'()'))
}
timethese 1_000_00, {
'regex' => sub {
regex($_) for @func;
},
'eval_f' => sub {
eval_f($_) for @func;
},
};
Benchmark: timing 100000 iterations of eval_f, regex...
eval_f: 16 wallclock secs (14.84 usr + 0.10 sys = 14.94 CPU) @ 6693.44/s (n=100000)
regex: 2 wallclock secs ( 1.42 usr + 0.01 sys = 1.43 CPU) @ 69930.07/s (n=100000)