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 DeltronicsIn reply to Re: Faster indexing an array
by CountZero
in thread Faster indexing an array
by wollmers
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |