Re: Slow code


Brian Christmas
 

G’day Karsten

Thank you very, very much.

I’ve made some further alterations, and in Script Debugger it takes a consistant 3.55 seconds now.

However, in my App, it now takes less than 2 seconds, whereas before the code I had was taking double the time it took in Script Debugger. I was waiting about 30 seconds.

Great thinking, my appreciation!

Regards

Santa


use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions
set l to ""
set f1 to 19480822
set f2 to 19471206
random number 1.0E+11 to 9.99999999999E+11 with seed my fixIt()
my doit()
on doit()
set collector to {}
set f1 to 19480822
set f2 to 19471206
random number 1.0E+11 to 9.99999999999E+11 with seed my fixIt()


repeat with x from 1 to 10000
set r1 to random number from 10 to 100
set r2 to random number from 10 to 100
set f1 to f1 + r1
set f2 to f2 + r2


set r3 to random number from 100000 to 999999
set r4 to random number from 100000 to 999999


set l to (f1 as text) & "-" & f2 & "-" & (r3 as string) & "-" & (r4 as string) & return
set end of collector to l
end repeat
set resultstring to collector as string
return resultstring
end doit


On 12 Sep 2017, at 9:57 pm, Karsten Wolf via Groups.Io <karstenwo@...> wrote:

Replacing all "as text" with "as string" shaves another 0.5s

-karsten





Join applescript@apple-dev.groups.io to automatically receive all group messages.