Re: processing time & stack overflow
Re: processing time & stack overflow
- Subject: Re: processing time & stack overflow
- From: Timothy Bates <email@hidden>
- Date: Tue, 28 Aug 2001 11:20:31 +1000
On 8/28/01 7:43 AM, "Victor Yee" <email@hidden> wrote:
>
Instead of [calling random numberrepeatedly], try this
>
>
to randomize(TheList)
>
repeat with i from length of TheList to 1 by -1
>
set current_item to some item of TheList's items 1 thru i
>
tell TheList -- exchange item current_item with item i
>
set temp to item i
>
set item i to item current_item
>
set item current_item to temp
>
end tell
>
end repeat
>
return TheList
>
end randomize
Victor, that construction is a great idea. The syntax is buggy (corrected
sysntax below), but the speed up is 10 X!
timing script =
set list1 to {}
repeat with n from 1 to 200
set end of list1 to n
end repeat
beep
set myTimer to install precision timer
randomize(list1)
set secondsElapsed1 to (stop precision timer myTimer)
set myTimer to install precision timer
randomizeOld(list1)
set secondsElapsed2 to (stop precision timer myTimer)
return {secondsElapsed1, secondsElapsed2}
--> {0.63353, 3.846826}
to randomize(TheList)
repeat with i from length of TheList to 1 by -1
set current_item to some item of TheList's items 1 thru i
tell TheList -- exchange item current_item with item i
set temp to contents of item i
set item i to contents of current_item
set current_item to temp
end tell
end repeat
return TheList
end randomize
to randomizeOld(TheList)
repeat with i from length of TheList to 1 by -1
set current_item to (random number from 1 to i)
tell TheList -- exchange item current_item with item i
set temp to item i
set item i to item current_item
set item current_item to temp
end tell
end repeat
return TheList
end randomizeOld
Dr Timothy Bates <
mailto:email@hidden>
Macquarie Centre for Cognitive Science (MACCS)
Macquarie University
Ph 61 (2) 9850 8623
Fx 61 (2) 9850 6059