in reply to Re: Can I speed this up? (repetitively scanning ranges in a large array)
in thread Can I speed this up? (repetitively scanning ranges in a large array)

Thanks. That's actually very similar to the original solution, but with in-lining the object method calls. Adopting this approach actually decreases running time by half. I'm always amazed how large it the overhead for calling functions, and it saddens me since it makes the code less maintainable and understandable. I guess you can't have it all...
  • Comment on Re^2: Can I speed this up? (repetitively scanning ranges in a large array)

Replies are listed 'Best First'.
Re^3: Can I speed this up? (repetitively scanning ranges in a large array)
by ikegami (Patriarch) on Nov 03, 2010 at 17:16 UTC

    I didn't "inline" for performance reason, I didn't create a sub because there was no reason to.

    my $dist = ($start - $end + 1) % $max_length;

    is perfectly fine without transforming it into

    my $dist = dist($start, $end); sub dist { my $start = shift // die; my $end = shift // die; if ( $end >= $start ) { # simple range return $end - $start + 1; } # warpped range return $max_length - $start + 1 + $end; }

    This is what I was explaining earlier.