Faster Shuffle?
- Posted by Thomas Mar 04, 2009
- 942 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