1. Faster Shuffle?

This shuffle routine is about 9 % faster than the one in sequence.e
shuffl.e
global function shuffle(sequence s)

randomly shuffle the elements of a sequence
written by Gabriel Boehme

based Jiri Babor's Euphoria interpretation of the "uniformly random"
1963 shuffle algorithm written by L.E. Moses and R.V. Oakford
integer r
object temp for i = length(s) to 2 by -1 do
r = rand(i)
temp = s[r]
s[r] = s[i]
s[i] = temp
end for
return s
end function



include std\sequence.e as new
include shuffl.e as old

atom start1, stop1
atom start2, stop2
object junk

start1 = time()
for i=1 to 10000 do
junk = new:shuffle(repeat(200, 300))
end for
stop1 = time()
?stop1 - start1

start2 = time()
for i=1 to 10000 do
junk = old:shuffle(repeat(200, 300))
end for
stop2 = time()
?stop2 - start2
?0
?(stop2 - start2) / (stop1 - start1)

~tj

while get_key()=-1 do

end while

new topic     » topic index » view message » categorize

2. Re: Faster Shuffle?

Ok, I added it in my local eu and can confirm it is faster. Old shuffle = 0.374, new = 0.312, gain of 0.83. Now, the question is, is it shuffled as well? That I am not sure how to test.

Any thoughts?

Jeremy

new topic     » goto parent     » topic index » view message » categorize

3. Re: Faster Shuffle?

jeremy said...

Ok, I added it in my local eu and can confirm it is faster. Old shuffle = 0.374, new = 0.312, gain of 0.83. Now, the question is, is it shuffled as well? That I am not sure how to test.

Any thoughts?

I've complete the analysis of the results and it is shuffled as well as it can be. I'll upload the changes now.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu