How can we dynamically create variable names from changing value "x" on a loop?

Ben Rubinstein benr_mc at cogapp.com
Tue Nov 8 12:48:47 CET 2016


On 07/11/2016 18:05, Richard Gaskin wrote:
>> I wouldn't care to hazard a guess as to the relative speed of
>> "aData[x]"  versus "item x": but it's the overhead of the function
>> which creates the array on that I don't want to pay *on every row*.
>
> The function call itself has very small overheard.  Whether the definition of
> that function takes more time than walking through the characters for the
> chunk expression can't be known without testing.

Not to flog this horse, but in this case it definitely does.

The point is that in my first pattern, I have outside the loop assigned column 
(item) indices to named variables (based on the items of the first, header, 
row). In the loop LC then has to locate the indexed items in an individual 
data row.

In the second pattern, the code which happens to be in a function for neatness 
has to create a new empty array, and chunk both the data row and the header 
row in order to get column names and values to put into the array. You can 
loop over one set of items, but not both, so LC still has to locate indexed 
items in at least one case.

So in short, the function is doing what the inline code is, plus a whole lot 
more. (Not to mention that in many cases the 'do something' code only acts on 
a subset of the items in each row, whereas the array of necessity is built out 
of all of them.) It may or may not be significantly slower; but it definitely 
is slower.

Ben




More information about the use-livecode mailing list