Re: which is faster (a repeat structure question)
Shao, In the example you give, I would bet the repeat with is faster, since it only has to do 128 replace statements, whereas the repeat for each would have to adjust each character one at a time. It probably depends on the size of what's being converted - if it's small, repeat for each, if it's large, repeat with (in *this* example). Just my thoughts without benchmarking it... Ken Ray Sons of Thunder Software Email: [EMAIL PROTECTED] Web Site: http://www.sonsothunder.com/ - Original Message - From: Shao Sean [EMAIL PROTECTED] To: Mail-List MetaCard [EMAIL PROTECTED] Cc: Mail-List MetaCard [EMAIL PROTECTED] Sent: Thursday, September 26, 2002 1:13 AM Subject: which is faster (a repeat structure question) repeat with i = 127 to 255 replace numToChar(i) with (= toUpper(baseConvert(i,10,16))) in inputData end repeat return inputData repeat for each char inputDataChar in inputData if (charToNum(inputDataChar) = 127) then put = toUpper(baseConvert(charToNum(inputDataChar),10,16)) after outputData else put inputDataChar after outputData end if end repeat return outputData is repeat for each really that much quicker? i realize that the amount of data being converted is a major factor, but the first one only needs to loop 128 times whereas the second one has to loop for each char, which could be well more than 128 chars.. TIA - Sean ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard
Re: which is faster (a repeat structure question)
In the example you give, I would bet the repeat with is faster, since it it's my actual code, i used to use the repeat for but switched that chunk to the repeat with as it seemed to be easier to just replace all of the instances at once... It probably depends on the size of what's being converted that's the unknown variable.. i don't assume too many people write 10,000 word essays for email messages (well, i do know one lady who does, but she's cool ;-) Just my thoughts without benchmarking it... thanks for sharing, but you can have them back now (they're getting soggy down here in the gutter =)~ ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard
Re: which is faster (a repeat structure question)
Shao Sean wrote: repeat with i = 127 to 255 replace numToChar(i) with (= toUpper(baseConvert(i,10,16))) in inputData end repeat return inputData repeat for each char inputDataChar in inputData if (charToNum(inputDataChar) = 127) then put = toUpper(baseConvert(charToNum(inputDataChar),10,16)) after outputData else put inputDataChar after outputData end if end repeat return outputData is repeat for each really that much quicker? i realize that the amount of data being converted is a major factor, but the first one only needs to loop 128 times whereas the second one has to loop for each char, which could be well more than 128 chars.. Try this: on mouseUp answer file Select a file: if it is empty then exit to top put url(file:it) into inputData put len(inputData) into tLen set the cursor to watch -- -- TEST 1 -- put the milliseconds into tStart repeat with i = 127 to 255 replace numToChar(i) with (= toUpper(baseConvert(i,10,16))) \ in inputData end repeat put the milliseconds - tStart into tTime1 put inputData into tOut1 -- -- TEST 2 -- put the milliseconds into tStart repeat for each char inputDataChar in inputData if (charToNum(inputDataChar) = 127) then put = toUpper(baseConvert(charToNum(inputDataChar),10,16)) \ after outputData else put inputDataChar after outputData end if end repeat put the milliseconds - tStart into tTime2 put outputData into tOut2 -- -- RESULTS -- if tOut1 tOut2 then put error on one of the algorithms else put Length: tLen replace: tTime1 \ repeat for each: tTime2 end mouseUp I got these results testing on three different files: Length: 2566replace: 22repeat for each: 5 Length: 16167replace: 99repeat for each: 35 Length: 204152replace: 1726repeat for each: 684 Perhaps on really large files the first method might be faster. It takes only a moment to verify questions of relative performance, well worth doing when you're looking for ways to optimize performance. To see other performance comparisons and conveniently run your own try MetaBench, a benchmarking tool for comparing script snippets: ftp://ftp.fourthworld.com/MetaCard/4W_MetaBench.mc.sit.hqx If you wanna see some really scary results, run the same test on equivalent Mac and PC machines -- Richard Gaskin Fourth World Media Corporation Custom Software and Web Development for All Major Platforms Developer of WebMerge 2.0: Publish any database on any site ___ [EMAIL PROTECTED] http://www.FourthWorld.com Tel: 323-225-3717 AIM: FourthWorldInc ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard
Re: which is faster (a repeat structure question)
put url(file:it) into inputData you store the data replace numToChar(i) with (= toUpper(baseConvert(i,10,16))) \ in inputData you convert the data -- TEST 2 but for test2 the data is still converted.. put the milliseconds into tStart repeat for each char inputDataChar in inputData if (charToNum(inputDataChar) = 127) then put = toUpper(baseConvert(charToNum(inputDataChar),10,16)) \ after outputData else put inputDataChar after outputData end if end repeat ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard
Re: which is faster (a repeat structure question)
how about a cross between the two? constant charsToReplace = 127,128,129,130,...,255 -- you get the idea repeat for each item i in charsToReplace replace numToChar(i) with (= toUpper(baseConvert(i,10,16))) in inputData end repeat test1 for me was _wy_ slow even at files of just a few hundred k (of course it's not meant to encode files, just text typed, but some people can be wordy ;-) test2 was much quicker.. i split the two tests into 2 seperate buttons to make both identical in their behaviour ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard
Re: which is faster (a repeat structure question)
Shao Sean wrote: put url(file:it) into inputData you store the data replace numToChar(i) with (= toUpper(baseConvert(i,10,16))) \ in inputData you convert the data -- TEST 2 but for test2 the data is still converted.. Good catch. I revised it as shown below and still get similar results. Oddly enough, on files containg binary data the outputs do not match. Should they? on mouseUp answer file Select a file: if it is empty then exit to top put url(file:it) into inputData1 put inputData1 into inputData2 put len(inputData1) into tLen set the cursor to watch -- -- TEST 1 -- put the milliseconds into tStart repeat with i = 127 to 255 replace numToChar(i) with (= toUpper(baseConvert(i,10,16))) \ in inputData1 end repeat put the milliseconds - tStart into tTime1 put inputData1 into tOut1 -- -- TEST 2 -- put the milliseconds into tStart repeat for each char inputDataChar in inputData2 if (charToNum(inputDataChar) = 127) then put = toUpper(baseConvert(charToNum(inputDataChar),10,16)) \ after outputData else put inputDataChar after outputData end if end repeat put the milliseconds - tStart into tTime2 put outputData into tOut2 -- -- RESULTS -- if tOut1 tOut2 then put error in one of the algorithms else put Length: tLen replace: tTime1 \ repeat for each: tTime2 end mouseUp -- Richard Gaskin Fourth World Media Corporation Custom Software and Web Development for All Major Platforms Developer of WebMerge 2.0: Publish any database on any site ___ [EMAIL PROTECTED] http://www.FourthWorld.com Tel: 323-225-3717 AIM: FourthWorldInc ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard
Re: which is faster (a repeat structure question)
file size: 1.61KB test1: 46 test2: 2 test3: 46 file size: 978KB test1: 47102 test2: 7444 test3: 46913 test3 is the other method i mentioned.. perhaps it's not the repeat that's slowing it down, but the actually replacing? for now it looks like i'll switch my code back to the slightly faster method 2.. all my tests were done through a windows compiled app (p3 800) ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard
Re: which is faster (a repeat structure question)
test3 is the other method i mentioned.. perhaps it's not the repeat that's slowing it down, but the actually replacing? for now it looks like i'll switch my code back to the slightly faster method 2.. I have a save handler that saves data changed in a standalone, and stores it in a stack, user preferences and the like. The handler works very quickly except for one part... There are about 30 fields in the standalone, with equivalent fields in the stack, and the save handler just put fld x of cd 1 of stack theStandalone into fld x of cd 1 of stack theStack. This handler was so slow, that instead of calling it every time there's a save, it only gets called when there's a change to those particular fields. (All the other data is one word or phrase, so one field could hold many pieces of data. All the globals that are one line are stored in the same field. The 30 fields handle a big chunk of data each, so they need to be stored separately from each other.) I toyed with the idea of creating 30 globals, putting the fields into the globals, and then putting the globals into the stack. We'll see how it performs on my testers machines as it is, and if changes are needed, will diddle some more. -- --Shareware Games for the Mac-- http://www.gypsyware.com ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard
which is faster (a repeat structure question)
repeat with i = 127 to 255 replace numToChar(i) with (= toUpper(baseConvert(i,10,16))) in inputData end repeat return inputData repeat for each char inputDataChar in inputData if (charToNum(inputDataChar) = 127) then put = toUpper(baseConvert(charToNum(inputDataChar),10,16)) after outputData else put inputDataChar after outputData end if end repeat return outputData is repeat for each really that much quicker? i realize that the amount of data being converted is a major factor, but the first one only needs to loop 128 times whereas the second one has to loop for each char, which could be well more than 128 chars.. TIA - Sean ___ metacard mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/metacard