When you time an empty repeat loop, you'll see that a substantial
part of the time of the whole process is actually just maintaining
the loop itself.
Brigaut's method only needs half as many iterations, and I believe
that is mostly why it's faster.
Brigaut's method was already pretty darn optimized, so in order to
impress uncle Wade, I had to do the old exploit, of unwrapping the
loop.
The unwrapping is the main factor here, attempting to reduce the
loop-loss by a factor 10, but I also threw in a bit of an inverted
Newton loop, just for good measure.
Futile perseverance, Jakob.
-- Welcome to Director --
test
-- "Colin: 525"
-- "Brigaut (optimized): 427"
-- "Hede: 355"
on testHede
tList = []
tList[100000] = "smurf"
tTime1 = the milliseconds
----
tCount = tList.count()
tCountHalf = tCount/ 2
tCountPlus1 = tCount + 1
----
tLower = tCountHalf
repeat while tLower
if tLower mod 10 then
-- first handle the surplus --
tUpper = tCountPlus1 - tLower
tTmp = tList[tLower]
tList[tLower] = tList[tUpper]
tList[tUpper] = tTmp
tLower = tLower - 1
else
-- then move in chunks --
repeat while tLower
tUpper = tCountPlus1 - tLower
tTmp = tList[tLower]
tList[tLower] = tList[tUpper]
tList[tUpper] = tTmp
tTmp = tList[tLower - 1]
tList[tLower - 1] = tList[tUpper + 1]
tList[tUpper + 1] = tTmp
tTmp = tList[tLower - 2]
tList[tLower - 2] = tList[tUpper + 2]
tList[tUpper + 2] = tTmp
tTmp = tList[tLower - 3]
tList[tLower - 3] = tList[tUpper + 3]
tList[tUpper + 3] = tTmp
tTmp = tList[tLower - 4]
tList[tLower - 4] = tList[tUpper + 4]
tList[tUpper + 4] = tTmp
tTmp = tList[tLower - 5]
tList[tLower - 5] = tList[tUpper + 5]
tList[tUpper + 5] = tTmp
tTmp = tList[tLower - 6]
tList[tLower - 6] = tList[tUpper + 6]
tList[tUpper + 6] = tTmp
tTmp = tList[tLower - 7]
tList[tLower - 7] = tList[tUpper + 7]
tList[tUpper + 7] = tTmp
tTmp = tList[tLower - 8]
tList[tLower - 8] = tList[tUpper + 8]
tList[tUpper + 8] = tTmp
tTmp = tList[tLower - 9]
tList[tLower - 9] = tList[tUpper + 9]
tList[tUpper + 9] = tTmp
tLower = tLower - 10
end repeat
end if
end repeat
----
put "Hede: " && the milliseconds - tTime1
end
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]