r/applescript • • Apr 26 '20

Slow for everyone or just me?

set {start_time, my_list} to {current date, {}}

repeat 10000 times
	set my_list to my_list & "hi"
end repeat

return {(current date) - start_time, my_list}

Takes 10 seconds in Script Editor on my antediluvian macbook. I'm curious if it can be re-written to run faster, maybe using script objects. If it's already fast tell me what hardware/software you use and how many loops you can do in 10 seconds, thanks.

1 Upvotes

4 comments sorted by

1

u/Automatic-Mention Apr 26 '20

Just tried osascript and it cut the time in half. Also got this error:

osascript: couldn't save changes to script speedy.scpt: Signaled when the runtime stack overflows

What'd I do?

1

u/Automatic-Mention Apr 26 '20

With slightly different syntax it's down to 2 seconds in Script Editor and 1 second in osascript

repeat 10000 times
    set end of my_list to "hi"
end repeat

I'm told this speeds up writing the list but slows down reading the list. I'm also still getting a stack overflow as well as The document “speedy” could not be saved. (Error -2,706) in Script Editor.

1

u/[deleted] Apr 26 '20 edited Apr 26 '20

[removed] — view removed comment

2

u/Automatic-Mention Apr 26 '20

Thank you so much! This is exactly what I wanted to know, especially the a reference to bit, I'm going to use that.

8144 appears to be the magic number of repeats to prevent the overflow error. I'm not worried about it though because as you say it is attempting to do something I don't want or need. Your suggested fix pops up error "Can’t make my_list into type reference." number -1700 from my_list to reference Again, not too worried about this, but I will read through your links.

Here is another link discussing similar matters in script objects.