Re: Is there any difference in accessing a variable vs object's proper

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I want to know whether there is any difference (such as performance) in accessing a variable which has been assigned the value of an object's property vs the object's property?

Accessing a property of an object has to lookup
Object reference pointer, then find the property
in the objects structure. So accessing the
variable copy can be faster, but that variable has to
be generated and then filled with that value of
the property. And finally, if you change the
value it has to be reassigned to the objects
property again.

Also acessing a variable can be slow, if you dont
use m dot. Accessing myVariable can be much slower
than accessing m.myVariable, as read acess of a
name expression first will first search, if there is a
field in the active workarea. With Write Access
that is not the biggest problem, but STORE
value To m.myVariable can be faster than
m.myVariable = value.

So using a var the right way could speed up tight
loops over many records or array rows, as the overhead
of first copying the value to a var is low compared to
overall saved time. But WITH..ENDWITH also helps
to cut the path to the objects structure, especially
with something nested as thisform.pageframe1.
pageX,pageframe1.PageY....

Write a testcase and see yourself:

pseudocode:

1.
t1=seconds()
var=object.property
loop
... var
endloop
?seconds()-t1

2.
t1=seconds()
var=object.property
loop
... m.var
endloop
?seconds()-t1

3.
t1=seconds()
loop
... object.property
endloop
?seconds()-t1

4.
t1=seconds()
with object
loop
... .property
endloop
endwith
?seconds()-t1

Bye, Olaf.
.



Relevant Pages

  • Re: wich is faster
    ... On the premature optimisation front - it has to be a judgement call by ... an "& 1" and a simple loop dividing n by odd numbers from 3 to sqrt. ... I do not accept that readability is an excuse ...
    (comp.programming)
  • Re: Awesome Tutorials for JavaScript beginners
    ... If the statement is false we exit from the while loop. ... Most Web developers think browser scripting is ... var UA = navigator.userAgent.toLowerCase; ... I suppose they could contact the authors of the script ...
    (comp.lang.javascript)
  • Re: slowing a script down
    ... When I add an alert to check it for each step of the loop, ... var stringWidth = new String; ... panelwidth = the character position where the string px is first found? ... can be re-used to animate any panel. ...
    (microsoft.public.scripting.jscript)
  • Re: Illegal LOOP usage?
    ... | reason would they even mention the WITH clause there? ... On the next iteration the loop variable would be bound with WITH to ... the constructs collect and collecting collect ... The argument var is set to the ...
    (comp.lang.lisp)
  • wait for event
    ... carry out a loop. ... var XYZDlg = function{ ... // This fires when the load event is initiated ...
    (comp.lang.javascript)