Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a performance implication of calling multiple objects in a row?

Call A:

double Value = Object.Object.Object.Object.DoubleValue;

Call B:

double Value : Object.DoubleValue;

If this were in a for loop and being called many times over and over would there be a performance loss for calling an object within an object or is it worth noting about?

like image 328
Oliver Dixon Avatar asked Dec 19 '12 14:12

Oliver Dixon


2 Answers

Readbility is for programmers, optimizations are for compilers (and jit optimizations, to be honest).

Do whatever is the standard in your team and is more readable.

If after you do it you suspect some performance issue - use a profiler to check if it is indeed the case, and do adjustments accordingly.

like image 152
amit Avatar answered Oct 16 '22 20:10

amit


is it not worth noting about?

Its could cost you tens of nano-seconds (is that important to you?) The JIT fairly good at optimising/caching reference look ups so placing them in local variable is unlikely to be mcuh faster. i.e. even if it matters there is unlikely to be something simple you can do about it.

like image 2
Peter Lawrey Avatar answered Oct 16 '22 19:10

Peter Lawrey