Benchmark: Behavior script access performance
ambassador at fourthworld.com
Wed Mar 11 20:14:41 CDT 2009
Benchmarking fiend that I am, I was curious about the overhead of
calling a hander in a behavior script in v3.5 as opposed to the closest
approximation in 3.0 and earlier, a backScript which differentiates
which objects it works on based on a custom property value.
For those unaware that v3.5 is in beta testing, Kevin introduced it in a
Trevor goes into detail here:
In brief, in v3.5 you can use the script of any button to define
behavior for any other object, enhancing the message path like this:
Messages sent to an object go first to that object, and then to whatever
button script is assigned as that object's behavior. After the behavior
script they resume the normal message path.
In v3.0 and earlier the closest thing we had was using a backScript and
then differentiating whether a handler should run or not based on the
value of a custom property. That was reasonably fast enough, but I
wondered if behaviors would be any faster.
So in v3.5b I made a stack with three buttons:
button 1 has a uClass property set to "b", with this benchmarking script:
put 10000 into n
put the millisecs into t
put foob() into r1
put the millisecs - t into t1
put the millisecs into t
put foobs() into r2
put the millisecs - t into t2
put t1 && t2
Button "b1" is inserted into the backScripts, with his handler:
if the uClass of the target = "b" then
Button "c1" is assigned as the behavior of button 1, with this script:
True, the backScript is being asked to do more work, but it's the
fairest comparison that way because behavior scripts only apply to
buttons with a property assigned to them (the behavior property), and do
not affect others.
So here's the result:
Behaviors average roughly three times faster to access than functionally
And FWIW, if I take out the property check in the backScript (which
gives the backScript method an unfair advantage), the result is:
So behaviors still win. Not surprising, since messages have a shorter
path to travel to them.
If you're not currently participating in the beta testing for v3.5 just
sit tight a while longer, it's coming. And when it's here, the new
behaviors feature will not only change the way you script, but in some
cases may boost performance along the way.
It's a mighty fine implementation. Thanks, RunRev!
Revolution training and consulting: http://www.fourthworld.com
Webzine for Rev developers: http://www.revjournal.com
More information about the use-livecode