Array faster than UArray Double, Was: ...speed of array types
Manuel M T Chakravarty
chak@cse.unsw.edu.au
Wed, 24 Jul 2002 17:20:43 +1000 (EST)
Jan Kybic <kybic@ieee.org> wrote,
> I have recently coded in Haskell a little program which evaluates
> a function given as a series of matrix products. Matrices and vectors
> are represented as type X. Surprisingly, compiled with 'ghc -O2'
> (vers 5.02.2) the program runs faster with X=Array than with X=UArray Double.
> I was quite puzzled by this result, I suppose that maybe the laziness
> helps to avoid memory allocation or something. Is that possible?
This should only have an effect if parts of the resulting
matrices were not used to compute the final result. Given
that the interface to H98 arrays heavily relies on lists for
generating arrays and extracting results, the list
computations can easily dominate the actual array
computations. If that happens, it often depends on how much
deforestation[1] GHC can perform.
Cheers,
Manuel
[1] Static removal of intermediate data structures