If I understand you correctly, your ranges are all essentially independent of each other.
One thing I would definitely suggest is buckets for the ranges. Have an array of 2k buckets, with each bucket covering 2000 values. For each range, push a reference to it into the buckets it touches. That way, you only have to inspect a couple of ranges (avg of 30-40 I expect) for each value, and it should speed up the calculation, at the cost of a little pre-processing work.
Addendum:On further thought, this would be quite different and possibly slower than your current scheme, which is pretty good.
For a refinement, what if you simplify the calculation of distance to the edge point? Try breaking up the for loop over the range into two loops. The first goes from zero distance from the start point up to max at halfway through the range. The second goes from max at halfway, down to zero at the end point.
Then you can simply say $score = max($score, $loopIndex);
In reply to Re: Can I speed this up?
by SuicideJunkie
in thread Can I speed this up? (repetitively scanning ranges in a large array)
by daverave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |