Benchmarks shouldn't change.
I think a 3% penalty is an affordable prize for clarity and easier chaining. (actually it's ignorable, Benchmark isn't that exact)
$ perl use Benchmark qw(cmpthese); package Example { sub new { bless {}, __PACKAGE__ } sub method { } } my $obj = Example->new; my $meth = 'method'; my $can = $obj->can('method'); cmpthese(-1, { direct => sub { $obj->method }, can2 => sub { $can->($obj) }, can3 => sub { $obj->$can() }, } ); __END__ Rate direct can3 can2 direct 893673/s -- -24% -26% can3 1180322/s 32% -- -3% can2 1214700/s 36% 3% --
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to Re^3: Optimizing non-alphanumeric method calls (update: benchmark)
by LanX
in thread Optimizing non-alphanumeric method calls
by trizen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |