Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Rewrite Program Using Arrays

by aaron_baugher (Curate)
on Mar 26, 2012 at 05:21 UTC ( #961586=note: print w/replies, xml ) Need Help??


in reply to Re^2: Rewrite Program Using Arrays
in thread Rewrite Program Using Arrays

There is no use for push/pop here, though. This is a pretty straightforward problem: counting the occurrences of words in a file. That means putting the words in a hash as the keys and incrementing the value when a word is seen. That's what you've done, so you're already using the best algorithm. You can gain some speed by cutting out any unnecessary assignments, as I showed with the benchmarks in my other post; but you certainly won't gain anything by using a less straightforward algorithm or by shuffling your words around through extra arrays. There really aren't "a lot of things you can do to speed the process." Building a hash and sorting on the values is as fast as it's gonna get, unless you want to rewrite it in C.

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961586]
help
Chatterbox?
[Eily]: LanX, let's hope it gets better for the second turn
vrk adds oatmeal cookies to the platter on the sideboard.
[LanX]: evrybody can participate in a YAPC
choroba is still undecided what to present at YAPC
[LanX]: imagine the stock market if the choice for the second round would have been those two ...
[robby_dobby]: LanX: Not me. No YAPC in my country and the only one in Asia is so far off in Japan
[LanX]: Oh I thought "Misery" meant Missoury
[LanX]: where do you live?
[LanX]: YAPC Asia was renamed and you'd need to speak Japanese to be able to follow
[robby_dobby]: LanX: Misery :P

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2017-04-24 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (442 votes). Check out past polls.