Apparently, which is slower depends on your version of perl... :-)
Here's the benchmark code I used. Now, it's not entirely fair because I'm not testing with a long list of parameters - Benchmark is going to only pass in a single parameter. However, it's a start.
#!/usr/bin/perl
sub dest { return 1 } # don't want it optimised away
use Benchmark qw(:all);
cmpthese(-1,
{
goto => sub {
goto &dest;
},
call => sub {
return dest(@_);
},
callamp => sub {
return &dest;
},
});
And the results? They depend on the version of perl. Using just the oldest and newest perls I have:
$ perl5.8.8 x.pl
Rate call callamp goto
call 4283398/s -- -9% -29%
callamp 4693114/s 10% -- -22%
goto 5996757/s 40% 28% --
$ perl5.14.1 x.pl
Rate call goto callamp
call 4633858/s -- -9% -12%
goto 5119310/s 10% -- -2%
callamp 5242879/s 13% 2% --
Of course, nothing of import is actually happening, the code in the called function will likely completely overwhelm the calling, so (and I'm sure you,
ikegami, know this)
don't base which one you use on the performance - there is no real significant difference - even the slowest one in perl 5.8.8 only takes 2.3e-7 seconds (on my CPU), which amounts to a couple hundred CPU cycles. Any REAL work you're doing will so completely overwhelm this that the so-called "savings" between calling it one way vs another will be nothing more than noise. Use the one that does what you mean, the maintainers (which likely will include yourself 6+ months from now) will thank you.