I hate it when I post too quickly. 0 ms was just too good to be true so I investigated further and found 2 errors in my code. The real figures are
10,000 Unicode Repeat Until: 19 ms Repeat for Each: 3 ms 100,000 Unicode Repeat Until: 1823 ms Repeat for Each: 30 ms 1,000,000 Unicode Repeat Until: 236688 ms Repeat for Each: 295 ms Which still proves the point that 'repeat for each' scales much better than other repeat forms. Corrected script below: on mouseUp --breakpoint --create a random list of 20 ASCII chars between ASCII32 - ASCII 125 set the useUnicode to false put empty into tLIST repeat 20 times put numToChar(random(94) + 31) after tLIST end repeat ask "How many characters do you want to process" with 100000 titled "Enter Digits Only - No Punctuation" put it into tNumOfChars answer "Do you wish to test against Unicode chars?" with "Yes" or "No" titled "Test Unicode" put it into tUniCode if (tUniCode = "Yes") then set the useUnicode to true put 65535 into tUpperLimit else put 255 into tUpperLimit end if repeat tNumOfChars times put numToChar(random(tUpperLimit)) after tORIGIN end repeat put the number of chars in tORIGIN into msg --so the 2nd test is identical put tORIGIN into tORIGIN2 --TEST 1 TIMING put the millisec into tStartTime repeat until tORIGIN is empty if tLIST contains the first char of tORIGIN then put the first char of tORIGIN after tOUTPUT delete the first char of tORIGIN else delete the first char of tORIGIN end if --put $ORIGIN into fld "fORIGIN2"--not required end repeat put tOUTPUT into tTest1 put the millisec into tEndTime put tEndTime - tStartTime into tTest1Time --TEST 2 TIMING put the millisec into tStartTime repeat for each char tChar in tORIGIN2 if (tLIST contains tChar) then put tChar after tOUTPUT2 end if end repeat put tOUTPUT2 into tTest2 --breakpoint put the millisec into tEndTime put tEndTime - tStartTime into tTest2Time --breakpoint if (tTest1 = tTest2) then put "Repeat Until: " & tTest1Time & " ms" & cr & \ "Repeat for Each: " & tTest2Time & " ms" into msg else put "Failed - Outputs not equal" into msg end if beep --breakpoint end mouseUp _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode