[Haskell-beginners] Improving Performance

Brent Yorgey byorgey at seas.upenn.edu
Sun Jul 1 18:09:38 CEST 2012


On Sun, Jul 01, 2012 at 12:38:14PM +0200, Robert Heumüller wrote:
> Hi again,
> 
> hoping to further increase performance i've decided to calculate
> the distances between all points ahead of time and store the distance
> values in a map of maps. Because of the symmetry of the matrix this
> should work in O(0.5*n^2). Could you please take a look at the code and
> tell me if this would be the way to go? I fear that i might actually
> loose performance due to the lookuptime of the treemap compared to
> recalculating the distance between two points?

Indeed, since calculating the distance between two points is so simple
(just a few arithmetic operations) I really doubt you will get much
speedup by caching the distances, especially if you have a lot of
points.  But, as always, it's really impossible to predict for
sure---you'll have to do some profiling.

-Brent



More information about the Beginners mailing list