in reply to Silly question about function args

The first is moderately faster from what I know, and Benchmark agrees.
use Benchmark 'cmpthese'; cmpthese -1, { 'shift'=> sub { my $x=shift; my $y=shift; my $z=shift; return }, 'assign'=> sub { my ($x,$y,$z)=@_; }, }; __END__ Benchmark: running assign, shift, each for at least 1 CPU seconds... assign: 2 wallclock secs ( 1.23 usr) @ 505470.78/s (n=622740) shift: 3 wallclock secs ( 1.01 usr) @ 435373.52/s (n=440598) Rate shift assign shift 435374/s -- -14% assign 505471/s 16% --
But when I add some even rudimentary code to the subs, like
for (1..100) { ++$x; $x+=$y+=$z }
the difference gets swamped to the point of being noise.
Benchmark: running assign, shift, each for at least 1 CPU seconds... assign: 2 wallclock secs ( 1.08 usr ) @ 7097.97/s (n=7680) shift: 1 wallclock secs ( 1.02 usr ) @ 6973.56/s (n=7120) Rate shift assign shift 6974/s -- -2% assign 7098/s 2% -- Benchmark: running assign, shift, each for at least 1 CPU seconds... assign: 2 wallclock secs ( 1.01 usr ) @ 7587.94/s (n=7679) shift: 2 wallclock secs ( 1.08 usr ) @ 7592.04/s (n=8207) Rate assign shift assign 7588/s -- -0% shift 7592/s 0% --
Go ahead and make the change, but Id be quite suprised if benchmark showed much difference.

You may need to make the function inline to see any real gains. Other tricks like using static variables (reduces allocation overhead but renders the code not thread safe). You may need to consider a lot of things. Poorly constructed regexes can chew up a lot of time. Without seeing the code and its usage theres no way anyone here could make any specific recommendations. :-)

You should have a look at When perl is not quite fast enough

HTH

--- demerphq
my friends call me, usually because I'm late....