Tested on a Roku 3
Count=10000000 ’ 10 million
X = 1000: SW = Epoch(): for Y = 1 to Count: Z = X: end for: ? Epoch()-SW
X = { X:1000 }: SW = Epoch(): for Y = 1 to Count: Z = X.X: end for: ? Epoch()-SW
m.X = 1000: SW = Epoch(): for Y = 1 to Count: Z = m.X: end for: ? Epoch()-SW
m.Global.AddFields({X: 1000}): SW = Epoch(): for Y = 1 to Count: Z = m.Global.X: end for: ? Epoch()-SW
… code to fill reg variable (as a string)… SW = Epoch(): for Y = 1 to 10,000,000: Z = RegistrySection.Read(“X”): end for: ? Epoch()-SW
2.187 seconds, 5.562 seconds, 5.548 seconds, 40.905 seconds, and 45.485 seconds respectively
An AA dereference is less than half the performance of a direct variable, that’s not a surprise as it is basically 2 variable references, but global access is almost as the same as registry read performance, 7 times slower than X.X, and 18 times slower than a direct variable, so global variables are rather expensive compared to other AA variables, I am assuming there is serialization/deserialization involved.
None of this matters except in high count tight loops. Out of habit I hoist global variables (and obviously registry variables) that are accessed more than once in a code block, so will definitely continue doing that in loops.
Epoch code is
function Epoch() as longinteger
TS = CreateObject(“roDateTime”)
return 1000& * TS.AsSeconds() + TS.GetMilliseconds()
end function
