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

Re: Optimizing I/O intensive subroutine

by chromatic (Archbishop)
on Oct 26, 2012 at 16:16 UTC ( #1001118=note: print w/ replies, xml ) Need Help??


in reply to Optimizing I/O intensive subroutine

What happens if you return an array reference instead of an array at the end of this function? (Depending on how large $limit is, you might cause Perl to copy a lot of data.)

What happens if, instead of reading the whole file into an array and then sorting it, you keep track of the largest n lines you've seen and read the file line by line?


Improve your skills with Modern Perl: the free book.


Comment on Re: Optimizing I/O intensive subroutine
Download Code
Replies are listed 'Best First'.
Re^2: Optimizing I/O intensive subroutine
by Anonymous Monk on Oct 26, 2012 at 16:30 UTC

    The latter suggestion is more promising.

    Looking at the timings, the bulk of the time is in the split (20.4 s) and the push @lines (16.2s)

      Ah, I didn't see there was a second image. Good catch.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2015-07-31 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls