Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Optimizing perl code performance

by Intermediate Dave (Novice)
on Aug 15, 2015 at 03:10 UTC ( #1138664=note: print w/replies, xml ) Need Help??


in reply to Optimizing perl code performance

Perl's core modules include 'Memoize', which attempts to make functions faster by "trading space for time."

http://perldoc.perl.org/Memoize.html

But I'd have to do trial-and-error to see what worked. (I'm wondering if a regExp would be faster than split)
/.*,.*,.*,.*,.*,.*,.*,.*,(*),.*/ my $X = $1
Then you wouldn't even need to call chomp. (And in general, I'm wondering if it would speed things up to combine the other instructions.)
chomp( my($line)=$_ ) ;
UPDATE: It occurred to me that the code re-declares every variable again on every pass through the loop. It seems like it might help to try
my ($X, $Y, $A, $B, $C, $D); while(<DATAIN>)

Replies are listed 'Best First'.
Re^2: Optimizing perl code performance
by QM (Parson) on Aug 17, 2015 at 09:33 UTC
    I'm wondering if a regExp would be faster than split.
    split takes a regex, so an optimized regex similar to the split could only be marginally better, and potentially much worse, especially for simple cases like this.

    Likewise chomp is very simple, and is probably zillions of times faster than IO.

    Profile, then fiddle. Lather, rinse, repeat.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1138664]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2020-12-01 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?