seed of setProp vs local vars vs globals

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ElZitouni
Posts: 33
Joined: Sun Oct 14, 2012 10:43 pm

seed of setProp vs local vars vs globals

Post by ElZitouni » Thu Dec 08, 2016 8:45 pm

Hello,
I am working on a custom video player controller, which offers the basic functions of the standard controller of the player object but adds functions my project needs.
This is the first time I used setProp/getProp to set the parameters of my custom control.
Now I wonder whether this was a wise, as I have the subjective impression setProp/getProp might execute slower than using local vars and accessor functions and/or global vars.
Any advice?
Thanks,
Olli.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: seed of setProp vs local vars vs globals

Post by dunbarx » Thu Dec 08, 2016 9:49 pm

Hi.

Not sure what you mean by speed issues. Those control structures are triggered by changes in (or queries of) custom properties. They are essentially "handler" names that receive a "message" derived from such actions.

But once "trapped", LC takes over. The only thing to watch is recursion.

Or do I have your question totally wrong?

Craig Newman

ElZitouni
Posts: 33
Joined: Sun Oct 14, 2012 10:43 pm

Re: seed of setProp vs local vars vs globals

Post by ElZitouni » Thu Dec 08, 2016 9:59 pm

Hello: sorry for not being clear enough.

My understanding is as follows: if i set a custom property using syntax "set the cMyProperty to tValue" it will trigger a cMyProperty message that will be captured by the setProp handler "setProp cMyProperty".

If I would use a local variable/accessor functions, i would use the syntax "set_MyProperty tValue", which will lead to the activation of handler "on set_myProperty pVal".

Finally, I could use global vars, and then I would use the syntax "put tValue into gMyProperty".


Thus, I wonder whether one of these methods takes less time to execute.

olli.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: seed of setProp vs local vars vs globals

Post by FourthWorld » Thu Dec 08, 2016 11:39 pm

The speed difference is probably best measured in microseconds, and since in this case it's in response to a user action any difference won't be noticeable. I'd just use whichever works most logically for your setup. If those values are effectively properties for the controller, using custom properties would be a natural fit.

If you want to measure the differences yourself, these tips on benchmarking may be helpful:
http://livecodejournal.com/tutorials/be ... vtalk.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: seed of setProp vs local vars vs globals

Post by dunbarx » Thu Dec 08, 2016 11:44 pm

Ah.

Variables are a bit faster. Though I bet it will not make a difference. In a button script:

Code: Select all

on mouseUp
   put the ticks into temp
   repeat 1000000
      get the tprop of me
   end repeat
   answer the ticks - temp
   
    put the ticks into temp
   repeat 1000000
    dothis
   end repeat
   answer the ticks - temp
end mouseUp

on dothis
end dothis

getProp tProp
end tProp
Craig

ElZitouni
Posts: 33
Joined: Sun Oct 14, 2012 10:43 pm

Re: seed of setProp vs local vars vs globals

Post by ElZitouni » Fri Dec 09, 2016 12:12 am

Thank you all for your help. I'll stick with the current design then, which was based on the data structure design. Olli.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”