1. Faster Shuffle?
- Posted by Thomas Mar 04, 2009
- 969 views
This shuffle routine is about 9 % faster than the one in sequence.e
shuffl.e
global function shuffle(sequence s)
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
2. Re: Faster Shuffle?
- Posted by jeremy (admin) Mar 04, 2009
- 957 views
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
3. Re: Faster Shuffle?
- Posted by DerekParnell (admin) Mar 04, 2009
- 942 views
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.