Parent of Target
Mark Waddingham
mark at livecode.com
Fri Aug 11 05:12:39 EDT 2017
On 2017-08-10 21:10, Richard Gaskin via use-livecode wrote:
> How might I measure the benefits of long ID caching?
It isn't long ids which are cached - it is ids.
I made a few adjustments, tweaked a few things to remove some overheads
which aren't relevant here:
private function MarkObjRef1 pCount
repeat with x = 1 to pCount
get the long id of button x of group 1 of card 1 of this stack
end repeat
end MarkObjRef1
private function MarkObjRef2 pCount
put the long id of group 1 of card 1 of this stack into tGrpObj
repeat with x = 1 to pCount
get the long id of button x of tGrpObj
end repeat
end MarkObjRef2
private function MarkObjRef3 pCount
repeat with x = 1 to pCount
get the long id of sObjRefsA[x]
end repeat
end MarkObjRef3
private function MarkObjRef4 pCount
repeat with x = 1 to pCount
get the long id of button id word 3 of sObjRefsA[x] of this stack
end repeat
end MarkObjRef4
I get these results for (100 iterations with) 1000 groups:
0.000801 - Method 1 - full expression by number
0.001399 - Method 2 - mixed expression
0.001786 - Method 3 - long ID only
0.000665 - Method 4 - ID only
0.000005 - Control
0.000796 - Method 1 wo Control - full expression by number
0.001394 - Method 2 wo Control - mixed expression
0.001781 - Method 3 wo Control - long ID only
0.00066 - Method 4 wo Control- ID only
And these results for (10 interations with) 10000 groups:
0.05243 - Method 1 - full expression by number
0.05965 - Method 2 - mixed expression
0.0498 - Method 3 - long ID only
0.00697 - Method 4 - ID only
0.00006 - Control
0.05237 - Method 1 wo Control - full expression by number
0.05959 - Method 2 wo Control - mixed expression
0.04974 - Method 3 wo Control - long ID only
0.00691 - Method 4 wo Control - ID only
Here you can see that:
Method 1 takes 65 times as long, even though the number of groups has
only increased 10 times
Method 2 takes 42 times as long, even though the number of groups has
only increased 10 times
Method 3 takes 30 times as long, even though the number of groups has
only increased 10 times
Method 4 takes 10 times as long - the same factor as the increase in
number of groups.
Here Method 4 is the only one truly exploiting the id cache to maximum
effect - Methods 2 and 3 both have a stack lookup too - which is *not*
currently cached.
The modified code is below.
Warmest Regards,
Mark.
=================
local sObjRefsA
on mouseUp
put 10 into n
put (the number of btns of grp 1) * n into tIterations
put 10000 into tCount
--------------
put the millisecs into t
repeat n
put MarkObjRef1(tCount) into r1
end repeat
put the millisecs - t into t1
--
put the millisecs into t
repeat n
put MarkObjRef2(tCount) into r2
end repeat
put the millisecs - t into t2
------------------
-- Last test requires that we first obtain the object refs to
-- measure the benefits of long ID caching:
repeat with i = 1 to the number of btns of grp 1
put the long id of btn i of grp 1 into sObjRefsA[i]
end repeat
--
put the millisecs into t
repeat n
put MarkObjRef3(tCount) into r3
end repeat
put the millisecs - t into t3
--
put the millisecs into t
repeat n
put MarkObjRef4(tCount) into r4
end repeat
put the millisecs - t into t4
put the millisecs into t
repeat n
put MarkObjRefControl(tCount) into r5
end repeat
put the millisecs - t into t5
put the millisecs into t
repeat n
put MarkObjRefControlStackLookup(tCount) into r6
end repeat
put the millisecs - t into t6
--------------------
put t1/tIterations &" - Method 1 - full expression by number " &cr \
& t2/tIterations &" - Method 2 - mixed expression" &cr \
& t3/tIterations &" - Method 3 - long ID only" &cr \
& t4/tIterations &" - Method 4 - ID only" &cr \
& t5/tIterations &" - Control" & cr\
& t6/tIterations & " - Control Stack Lookup" & cr
put (t1 - t5)/tIterations &" - Method 1 - full expression by number "
&cr \
& (t2 - t5)/tIterations &" - Method 2 - mixed expression" &cr \
& (t3 - t5)/tIterations &" - Method 3 - long ID only" &cr \
& (t4 - t5)/tIterations &" - Method 4 - ID only" after msg
end mouseUp
private function MarkObjRef1 pCount
repeat with x = 1 to pCount
get the long id of button x of group 1 of card 1 of this stack
end repeat
end MarkObjRef1
private function MarkObjRef2 pCount
put the long id of group 1 of card 1 of this stack into tGrpObj
repeat with x = 1 to pCount
get the long id of button x of tGrpObj
end repeat
end MarkObjRef2
private function MarkObjRef3 pCount
repeat with x = 1 to pCount
get the long id of sObjRefsA[x]
end repeat
end MarkObjRef3
private function MarkObjRef4 pCount
repeat with x = 1 to pCount
get the long id of button id (word 3 of sObjRefsA[x]) of this
stack
end repeat
end MarkObjRef4
private function MarkObjRefControl pCount
repeat with x = 1 to pCount
end repeat
end MarkObjRefControl
private function MarkObjRefControlStackLookup pCount
repeat with x = 1 to pCount
get the long id of (word 13 to 14 of sObjRefsA[x])
end repeat
end MarkObjRefControlStackLookup
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list