I just copied a groklaw page into a text member (about 63K) and ran the above on a dual mirror 1.25GHz G4. (10.2.6) Here are the results:
-- 63679 -- "Walk: 14603" -- "Delete: 9509"
I added this to your routine:
reallyBigString = parentString
myCodeList = []
start = the milliseconds
wcnt = reallybigstring.word.count
repeat with w = 1 to wcnt
thisbit = reallyBigString.word[1]
cnt = thisbit.length
repeat with i = 1 to cnt
append(myCodeList, charToNum(thisbit.char[i]))
end repeat
if w < wcnt then
append(myCodeList, 32)
delete word 1 of reallyBigString
end if
end repeat
put "Delete Words: " & string(the milliseconds - start)and on my 1 GHz iMac saw this:
test -- 72540 -- "Walk: 29125" -- "Delete: 21993" -- "Delete Words: 2956"
I think the real slowdown in the approach is that when you ask for the nth character of a string it takes n times some amount to grab that character (which in a 70000 character case would mean an average of 70000*35000*that amount). In your optimized case you were trading 63679 of those walk through the list for 63679 deletes of the first character, and that will take some time, but not as much time. Hence your reduction from 14603 to 9509. With my longer string and slower processor that translated to 29125 reduced to 21993.
My addition to your routine take the data in word chunks, and uses your delete approach too. That means its only ever grabbing the first word, and then it is walking through the characters of that word, but it never has too far to walk. The result is an overall reduction of 29125 down to 2956, close to ten times faster.
Interestingly, if I change the character walk through of the word so that it uses the delete approach too, the routine becomes slower.
By the way, I'm surprised that the much bigger problem hasn't shown up, and that is that you can't deal with zero as a string. If the original need was to decipher images, surely you get cases where the data equals zero?
[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!]
