As far as I can tell, all contributions to this thread thus far are using the same variable as their source, so it's about as even as one could expect.[-hh] wrote:But this is my concern, if a scenario has an impact on the performance this impact should be at about the same for all functions.
There are, however, nuances which should be kept in mind when doing this sort of testing, but which are difficult, if not impossible, to account for when attempting to measure them.
The role of the OS in caching instructions and data is one, and we might see some small benefit from alternately reversing the order in which each of the two versions is called. But even then, we can expect slightly different results when running during a long session and when running fresh from a cold boot.
And then of course there's the impact of the many background tasks that most computers will be running concurrently with any test we'll be running, eating CPU cycles behind the scenes.
I don't believe it's possible, or at least practical, to try to account for such subtleties. Dick Kriesel may be able to come up with a way to minimize their impact (he's an uncommonly clever thinker), but I don't believe we can eliminate their effects entirely.
So when benchmarking we must be willing to accept loose approximation as the only outcome possible. Where we find significant advantage we're probably onto something useful, but where the results are frequently close we can never be sure whether it's because of the algo or the side effects of other things happening on the system.
FWIW, some years ago Wil Dijkstra took the time to post three interesting sets of tips on performance to the MetaCard list (the old name for what has since been renamed "LiveCode"):
http://lists.runrev.com/pipermail/metac ... 04415.html
http://lists.runrev.com/pipermail/metac ... 04469.html
http://lists.runrev.com/pipermail/metac ... 04539.html
Of those, I found the last one especially interesting, as it describes the impact of variable allocation and access on overall throughput.
Since LiveCode makes doing so many things so easy, we often take for granted the impact of seemingly small things like variable access, but Wil's third article illustrates well how even statements that seem simple enough can have an impact on what the engine is required to do to fulfill the request.
The sort of experimentation encouraged by threads like this one can be very helpful in identifying good habits to adopt in coding. Thank you for starting this discussion.