Size of array
Mark Smith
mark at maseurope.net
Sat Nov 17 21:25:21 EST 2007
Yes, but you can make the keys sort of multi-dimensional: someArray
[a,b,c], so for some purposes this works just as well.
In fact (note to shari), depending on your particular application,
you may find it more efficient to have an array with 300 * 1000
elements than to have an array with 300 elements of 1000 items each.
Though rev's chunk expressions are extremely efficient, accessing the
thousandth item in a list is generally going to be slower than
accessing an array element, even in a big array.
Put this in a button script:
on mouseUp
if the optionkey is down then
makeArrayWithItems
else
makeArrayNoItems
end if
end mouseUp
on makeArrayWithItems
repeat 300
add 1 to c
repeat 1000
put random(125676) & comma after sArray[c]
end repeat
end repeat
put the millisecs into st
repeat 10000
put random(300) into c
put 900 into d
get item d of tArray[c]
end repeat
put the millisecs - st
end makeArrayWithItems
on makeArrayNoItems
repeat 300
add 1 to c
put 0 into d
repeat 1000
add 1 to d
put random(125676) into sArray[c,d]
end repeat
end repeat
put the millisecs into st
repeat 10000
put random(300) into c
put 900 into d
get tArray[c,d]
end repeat
put the millisecs - st
end makeArrayNoItems
on my machine, though it seems to take a little longer to build the
no-items array than the with-items array, access is nearly 4 times
faster for the no-items array. The bigger the data, the more
pronounced then effect (try making it 500 x 2000, or 1000 x 5000).
Of course it's unlikely that you'll be accessing the 900th+ item all
the time, but it illustrates a worst case. Accessing the 1st item
every time produces a tie, so on average, the no-items array is going
to be faster.
Best,
Mark
On 18 Nov 2007, at 01:56, Petrides, M.D. Marian wrote:
> Speaking of arrays... Am I correct in understanding that Rev only
> supports one dimensional arrays or am I misreading the dox?
>
> On Nov 17, 2007, at 7:54 PM, Mark Smith wrote:
>
More information about the use-livecode
mailing list