valueDiff for arrays?
Brian Milby
brian at milby7.com
Sun Aug 5 19:29:23 EDT 2018
Earlier in this thread it was mentioned that LCS doing a loop once would
probably outpace the engine looping 2 times + a LCS loop at some point. I
decided to see if I could figure out a point where this might take place.
My test was pretty simple. I set a target number of elements for each
array. 1/3 have the same key and value, 1/3 have the same key but
different values, 1/3 are non-matching keys. Somewhere just over 50,000
keys the quickest version switches. Here's the code:
function bwmValueDiffPut pLeft, pRight
local tResult, tLeft, tRight
repeat for each key tKey in pLeft
if tKey is among the keys of pRight and \
pLeft[tKey] is not pRight[tKey] then
put pLeft[tKey] into tLeft[tKey]
put pRight[tKey] into tRight[tKey]
end if
end repeat
put tLeft into tResult["1"]
put tRight into tResult["2"]
return tResult
end bwmValueDiffPut
As anything, the real data set would impact the results significantly. For
example, the above code does the "among" test for every key. It does the
"is not" test for 2/3 of the keys. It does the pair of put statements for
1/3 of the keys. As that mix changed, the results would too - changing the
point at which this method would be the fastest. But to put it into
perspective, the 50,000 key test took around 75ms for both methods.
100,000 keys came in around 150ms on my machine.
I will also note that the dual loop delete method for LCS always lost and
by a significant margin (deleted from left first, deleted from right
second). The combination delete/put loop was slightly slower than the
above code (deleted from left, created new right as above). Also, Mark's
version was faster than my revision. I'm thinking that was due to the way
I was going into a second level array (tResult["2"][tKey] vice
tRight[tKey]).
More information about the use-livecode
mailing list