[Haskell-cafe] poor perfomance of indexU in uvector package

Alexey Khudyakov alexey.skladnoy at gmail.com
Sun Nov 15 10:16:03 EST 2009


On Sun, Nov 15, 2009 at 5:50 PM, Felipe Lessa <felipe.lessa at gmail.com> wrote:
> On Sun, Nov 15, 2009 at 03:00:34PM +0300, Alexey Khudyakov wrote:
>> Naive implementation using lists and index lookup.
>>   2.15 second for 200*200 array
>> > sliceXlist :: Int -> UArr Double -> [UArr Double]
>> > sliceXlist n a = map mkSlice [0 .. n-1]
>> >     where
>> >       mkSlice x = toU $ map (\y -> indexU a (x + y*n)) [0 .. n-1]
>
> Have you tried something like
>
>  mkSlice x = mapU (\y -> indexU a (x + y*n)) $ enumFromToU 0 (n-1)
>
> I guess it should be a lot faster :).

No it doesn't. There is no significant difference between two variant above.
I think any program which uses indexU will be slowed to crawl.
Seems like a bug for me.


>   Another implementation you may try is
>
>  a' = mapU (\(i :*: x) -> (i `mod` n) :*: x) (indexedU a)
>  mkSlice j = fstU $ filterU (\(i :*: x) -> i == j) a'
>
This one is fastest so far


> Also, I would recomend using criterion.

I tried to do so.. But it depends on gtk2hs and it is too difficult
to install


More information about the Haskell-Cafe mailing list