in reply to Silly question about function args
But when I add some even rudimentary code to the subs, likeuse 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% --
the difference gets swamped to the point of being noise.for (1..100) { ++$x; $x+=$y+=$z }
Go ahead and make the change, but Id be quite suprised if benchmark showed much difference.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% --
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....
|
|---|