Repeat Loop Execution Speed

I encountered an oddity when using a repeat loop to process a large number of items and thought I’d mention it FWIW.

The following shortcut gets and uppercases every paragraph of text from a file. The timing result with a file that contained 500 paragraphs was 17.96 seconds.

The following shortcut is identical to the above except that it uses the repeat loop’s internal list to store and return the uppercased text. The timing result was 4.88 seconds.

Just to verify, I ran additional tests in which the contents of a list with 500 items were simply added back to a new list in a repeat loop, and the timing results were 9.73 seconds for a manual list and 0.68 second for the internal list.

Some of the above timing results are not acceptable for actual use, and an AppleScript should be considered instead. However, if that’s not possible, the use of a manual list should be avoided. Fortunately, when a smaller number of list items are being processed, the timing results are generally a small fraction of a second whichever approach is used.

This test seemed a bit lame, so I retested with a text file that contained 500 paragraphs that alternated the following paragraphs:

This is line
This is line two

The shortcuts added the word one to paragraphs that ended with the word line.

The shortcut that used a manual list:

The shortcut that used the repeat loop’s internal list: