Timing oddity
Geoff Canyon
gcanyon at gmail.com
Sat Jan 25 01:31:40 EST 2014
10 11.326327 0.710837 15.933786
100 11.854238 0.662299 17.898622
1000 12.105847 0.698076 17.341732
10000 12.502957 0.773339 16.167497
100000 13.145294 0.813667 16.155618
1000000 12.737516 0.886334 14.371008
I ran the code below and got those numbers. I had assumed that array math
would be faster than iterating manually, and it is, but I also assumed that
the speed difference would increase for larger arrays, and it doesn't --
the array math is about 16 times faster, almost regardless of the array
size.
Oddly, on a different Macbook, the ratio was about 6, again for multiple
sizes of the target array. Not sure why that would be.
*on* mouseUp
*repeat* with arrayLog = 1 to 6
*put* 10^arrayLog into arrayCount
*put* 10^(7 - arrayLog) into repeatLoopCount
*repeat* with i = 1 to arrayCount
*put* random(100) into X[i]
*put* random(10) into Y[i]
*end* *repeat*
*put* the long seconds into T
*repeat* repeatLoopCount
*repeat* with i = 1 to arrayCount
*add* Y[i] to X[i]
*end* *repeat*
*end* *repeat*
*put* the long seconds - T into T1
*put* the long seconds into T
*repeat* repeatLoopCount
*add* Y to X
*end* *repeat*
*put* the long seconds - T into T2
*put* arrayCount && T1 && T2 && T1 / T2 & cr after R
*delete* variable X
*delete* variable Y
*end* *repeat*
*put* R
*end* mouseUp
More information about the use-livecode
mailing list