[clean-list] Re: Fastest shuffle with Clean?

Siegfried Gonzi siegfried.gonzi@kfunigraz.ac.at
Wed, 12 Sep 2001 09:27:17 +0200


CaptnJamesKirk@aol.com CaptnJamesKirk@aol.com schreibt:

> Greetings all,


Kuess' die Hand.

==
shuffleArray :: *{#Int} !Int -> *{#Int}
shuffleArray ar top
    | top < 0   = ar 
    | otherwise
        #! r = randomInt mod (top+1)
        #! rnd_elem = ar.[r]
        #! top_elem = ar.[top]
        = shuffleArray {ar & [r]=top_elem, [top]=rnd_elem} (top-1)


Is this the most efficient (read: fastest) way to shuffle an array in
Clean? 
==

a) How big are your arrays normally?

Often it depends whether the array finds its place in the cache or only
in the memory.

b) I think the above version should be very fast (I did something
similar with my FFT implementation). 

c) Do you have got any figures what do you expect concerning the
performance? If Clean woul be only lets say 1.5 times slower than a C
version I would have to say this is way okay! But the case Clean would
be 10 times slower I vote then there is a faster version in Clean
possible.

d) I am not sure how the randomInt function impedes the performance? Try
the version (for test cases only and independent of your random
problem!) also with array indices which becomes updated in shuffleArray
only, e.g. only with "top" and some shift and without randomInt. Then
you can see whether there is a performance slow-down from randomInt.

e) What is your Clean version and what is your processor and platform?


S. Gonzi