I was interested in one of the pull requests that mentioned a performance increase.
The changes included the use of elements of an array and I looked up the API as read... (I have reformatted it)
-----
The structure <
Code: Select all
repeat for each element myElement in myArray
...
end repeat
is equivalent to
Code: Select all
repeat with x = 1 to the number of lines in the keys of myArray put myArray[line x of the keys of myArray] into myElement
...
end repeat
However, the first form, using the element keyword, is much faster.
-----
I was interested if there was an appreciable gain as I do a lot of array processing in my app.
I decided to time the two forms to see if it was worth my while to change my existing handlers.
The first thing I discovered was that, with respect to repeat loops, elements only works with one dimensional arrays.
I also discovered that you mileage will vary as the assertion of "for each element" being much faster is not quite true.
I tested repeat loops with the following forms:
T1
Code: Select all
repeat with x = 1 to the number of lines in the keys of tarray
Code: Select all
put the number of lines in the keys of tarray into tx
repeat with x = 1 to tx
Code: Select all
repeat for each element x in tarray
Testing 1000 repetitions upon and array of 1000 elements.
t1 : 0.002021 (0.001,0.007)
t2 : 0.002018 (0.001,0.008)
t3 : 0.002452 (0.002,0.014)
As you can see the "for each element" form is not all it is cracked up to be.
Wondering if the comment was PRE LC 8 I decided to run the test in LC 6.7
Testing 1000 repetitions upon and array of 1000 elements.
t1 : 0.000812 (0,0.002)
t2 : 0.000803 (0,0.002)
t3 : 0.000614 (0,0.001)
Array operations are blistering fast in LC 6.7 AND the for each element for is faster.
Moral of the story: If the API says something is faster, try it out. What may have been the case pre 7 may no longer hold.