Which is faster?
<p>Which of these is more efficient in terms of speed (number of lines of code generated).</p>

<pre><code>var x=obj.mem;
x.do1();
x.do2();
</code></pre>

<p>or</p>

<pre><code>obj.mem.do1();
obj.mem.do2();
</code></pre>

<p>I just wrote those in a generic pattern. Specifically, if I have to access a member( or a member of a member ) , is it better to assign the common part to a variable and then use that variable or to call it directly as shown in the second case. </p>

<p>I'm concerned mainly about C++ and JavaScript (if it matters).
Thank You.</p>

<p>EDIT->
PS.I did not ask a common answer. I understand that Javascript is an interpreter language while C++ is compiler based. The little knowledge I have of JavaScript is self taught and we learned C++ for 2 years at school (and that too Turbo C++) and the rest is again self taught. So, forgive me for the confusion. I was expecting a general result assuming that the constructs are valid and considering any possible variations. Anyway, my major doubts were cleared. Thanks.</p>

<p>Conclusion: JS is faster with local variables (though negligible) and C++ will probably optimise to get almost equal results.</p>

<p>Thank You for all the input.</p>
