Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
Hello Everyone,
A question asked in my last day interview that which gives the better performance.
1. The less lines of code or the more lines of code.
2. How to improve the performance of application if you have assigned to an application for performance testing.


I was not able to satisfy the interviewer by my answers.

So please suggest me some ideas how to improve the performance of an application
and less code is better or more lines of code.



Thanks in Advance..

Regards,
Kumar Aryan.
Posted

It is not a rule, but best performant languages (like C/C++) are usually more verbose.
That's makes sense: in order the get the best performance from the hardware you need more control so you are going to go deep in details.
Of course you should always choose a good tradeoff between performant and elegant code, because: "more lines of code you write, more mess you have to maintain" :-)
 
Share this answer
 
Hi,

Performance :
Its not depends on lines of code, but it depends on use of variables and their lifetime scope, if you split your batch process in different function then it will boost your performance.

Approach would be different for Web and desktop application.

Performance is depends on requirement and environment in the time of designing if you could not find proper technology to target environment then it would be a total mess, now you need to understand and prioritize your process to get better performance.

What you can do ?
1. Parallel Processing
2. Caching
etc...

Here is good link which will provide you a good idea about application performance boosting : http://msdn.microsoft.com/en-in/library/ff647813.aspx[^]

Better utilize your resource will give best performance.
 
Share this answer
 
Comments
Kumar_ Aryan 30-Sep-14 2:53am    
Thanks Suvabrata,
The above link was very helpful.
Suvabrata Roy 30-Sep-14 5:25am    
Its my pleasure...
As far as my knowledge is concern, performance is not depends on number of coding lines but how you performing operation and number of resources you are using during your application lifetime and releasing them when they are not in use.

Second thing i want to tell you that performance increase can be done through analysis of application through performance measurement tools available and then make appropriate changes to your application code to meet the requirement.

If you follow above factor then it will automatically minmize the line of code so you can say that better code will have no dependency on line of code but it totally depends on how you are carried out your operation with best usages of technology.
 
Share this answer
 
Comments
Kumar_ Aryan 29-Sep-14 2:55am    
Thanks Ashok,
I little clear that lines of code doesn't matter in performance.

Thanks a lot.
At first sight there is no dependency between lines of code and the performance of that code. Just look at these two statements:
C++
a = b + c;

a
=
b
+
c
;

The first one takes one line, the second one six lines. Nevertheless, they will end up generating exactly the same code.

However, leaving such unusual cases out of consideration, there are some relations between lines of code and the run-time efficiency of that code.

(a) Optimizing a give piece of code ofter leads to more code lines.

One of the optimization techniques is loop unrolling. This often helps to optimize code with an inner loop of a fixed number of iterations. By writing manually down a number of iterations, the loop overhead is reduced and the compiler is given more opportunities to juggle with temporary variables and registers. This clearly leads to more lines of code. Other optimization techniques also have a tendency to lead to more lines of source code.

(b) Refactoring "clumsy" code often leads to better performance and less lines of code.

In all practical cases I have seen, re-implementing a badly written piece of code in a clearer way leads to a reduction of code lines and sometimes better performance. Hence, the rule: "Optimization leads to more code lines", cannot always be applied.

So, there is no general dependency between number of code lines and performance. BUT, it can be said: Doing performance optimization on a well written piece of code often leads to more code lines.
 
Share this answer
 
From a Java developers point of view:

- use TDD (test driven development)
- use J2EE strictly! (which leads to much more lines of code!)
- write test as you code (not later - that would be never!)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900