randomly order a list
Dar Scott
dsc at swcp.com
Wed Jun 5 20:54:38 EDT 2013
Here are some timings of random functions going in another direction.
Results for an old mac mini:
Works better on OS X.
Time for a 1000 X loop divided by 1000.
<nothing>134 ns
get empty 227 ns
get alphabet 288 ns
get random(9999999) 327 ns
get md5Digest(alphabet) 890 ns
get md5Digest(startLongSeconds & alphabet) 1837 ns
get md5Random() 2134 ns
on mouseUp
set the numberFormat to 0.
put "Works better on OS X." & lf into field 1
put "Time for a 1000 X loop divided by 1000." & lf after field 1
put "abcdefghijklmnopqrstuvwxyz" into alphabet
put the long seconds into t1
repeat 1000 times
end repeat
put the long seconds into t2
put "<nothing>" & (t2-t1)*1000000 & " ns" & lf after field 1
put the long seconds into t1
repeat 1000 times
get empty
end repeat
put the long seconds into t2
put "get empty " & (t2-t1)*1000000 & " ns" & lf after field 1
put the long seconds into t1
repeat 1000 times
get alphabet
end repeat
put the long seconds into t2
put "get alphabet " & (t2-t1)*1000000 & " ns" & lf after field 1
put the long seconds into t1
repeat 1000 times
get random(9999999)
end repeat
put the long seconds into t2
put "get random(9999999) " & (t2-t1)*1000000 & " ns" & lf after field 1
put the long seconds into t1
repeat 1000 times
get md5Digest(alphabet)
end repeat
put the long seconds into t2
put "get md5Digest(alphabet) " & (t2-t1)*1000000 & " ns" & lf after field 1
put the long seconds into startLongSeconds
put the long seconds into t1
repeat 1000 times
get md5Digest( startLongSeconds & alphabet)
end repeat
put the long seconds into t2
put "get md5Digest(startLongSeconds & alphabet) " & (t2-t1)*1000000 & " ns" & lf after field 1
put the long seconds into t1
repeat 1000 times
get md5Random()
end repeat
put the long seconds into t2
put "get md5Random() " & (t2-t1)*1000000 & " ns" & lf after field 1
end mouseUp
local randomState = true
private function md5Random
if randomState then put the long seconds into randomState
put md5Digest(randomState) into randomState
return randomState
end md5Random
More information about the use-livecode
mailing list