Re: Slow code


Karsten Wolf
 

- Try using a list of strings instead of the string "l". It gets resized 10000 times.


- If it's time critical, try using a different language. AppleScript was not designed for this. A quick Python implementation ran in 0.2s


-karsten


This here clocks at about 5-6s

use AppleScript version "2.4"

use scripting additions


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 1000000 to 10000000
set r4 to random number from 1000000 to 10000000
set temp to (r3 as text) & (r4 as text)


set l to (f1 as text) & "-" & f2 & "-" & (characters 1 through 6 of temp) & "-" & (characters 7 through 12 of temp) & return
set end of collector to l
end repeat
set resultstring to collector as string
return resultstring
end doit


on fixIt()
set c1 to "743196734015346789"
set c2 to "025694701243831634"
set c3 to "690116383350418453"
set x to characters 9 through 14 of c1 & characters 2 through 8 of c2 & characters 11 through 15 of c3 as text as integer
return x
end fixIt

doit()


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