in reply to Inlining method/function calls?

Suggestion. Perform the test for existance inline and only call the function if the value must be extracted from the header. The overhead of the function call will likely be lossed in the code of invoking the regex engine.

Question: Why do you use that substr expression? You have captured the value to $1 (if it exists) in order to set @- and @+. Why not just use $1?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re: Re: Inlining method/function calls?
by diotalevi (Canon) on Jul 28, 2003 at 03:22 UTC

    Because capturing is the most expensive thing that happens there. On a ten minute program I shaved a minute off by avoiding capturing groups (you mistook (?>...) for a capture block) and using substr instead. A minute is pretty small for the thirty megabyte data set I was working with, I just expected most data sets to be half a gig or more. I picked a simpler example for this code sample - it still illustrates the point (and verified through dprof).

    unless ($$buffer =~ m/^H=(?>\d+);/) { confess "$rec_num was missing the header prefix m/^H=\\d+;/: $$buf +fer"; } my $header_length = substr $$buffer, 2, $+[0]-3; # vs unless ($$buffer =~ m/^H=((?>\d+));/) { confess "$rec_num was missing the header prefix m/^H=(\\d+);/: $$b +uffer"; } my $header_length = $1;