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 recent newsletter:
<http://runrev.com/newsletter/february/issue65/newsletter1.php>

Trevor goes into detail here:
<http://runrev.com/newsletter/february/issue65/newsletter2.php>

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:

   <control>
       <behavior>
   <card>
   <stack>

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:

on mouseUp
  put 10000 into n
  -- Behavior:
  put the millisecs into t
  repeat n
    put foob() into r1
  end repeat
  put the millisecs - t into t1
  -- Backscript:
  put the millisecs into t
  repeat n
    put foobs() into r2
  end repeat
  put the millisecs - t into t2
  -- Result:
  put t1 && t2
end mouseUp


Button "b1" is inserted into the backScripts, with his handler:

function foobs
  if the uClass of the target = "b" then
    return 1+1
  end if
end foobs


Button "c1" is assigned as the behavior of button 1, with this script:

function foob
  return 1+1
end foob

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:

9 30

Behaviors average roughly three times faster to access than functionally equivalent backScripts.

And FWIW, if I take out the property check in the backScript (which gives the backScript method an unfair advantage), the result is:

9 16

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!

--
 Richard Gaskin
 Fourth World
 Revolution training and consulting: http://www.fourthworld.com
 Webzine for Rev developers: http://www.revjournal.com
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to