in reply to Faster indexing an array
should be a bit faster as it eliminates one step of indexing.push @{$YPos->{$_}}, $index++ for @$Y;
As an aside, why do you use scalars and references rather than arrays and hashes?
Update:
I ran your code on an array of 10 million elements. It took 27 seconds. My code finished in 20 seconds. Using arrays and hashes instead of scalars and references made it run in 19 seconds, another 5% saved!
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Faster indexing an array
by wollmers (Scribe) on Sep 19, 2014 at 22:09 UTC | |
by LanX (Saint) on Sep 19, 2014 at 22:34 UTC | |
by LanX (Saint) on Sep 19, 2014 at 23:17 UTC | |
by wollmers (Scribe) on Sep 20, 2014 at 06:54 UTC | |
|
Re^2: Faster indexing an array
by SuicideJunkie (Vicar) on Sep 19, 2014 at 21:33 UTC | |
by doom (Deacon) on Feb 17, 2015 at 22:23 UTC |