Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to do optimization during initial coding?

Tags:

optimization

Is it a good practice to follow optimization techniques during initial coding itself or should one concentrate purely on realization of functionality first?

If one concentrates purely on functionality during initial coding, then how easy or difficult is it to take care of optimization later on?

like image 926
Jay Avatar asked Jan 19 '10 09:01

Jay


People also ask

Is code optimization necessary?

Optimization is necessary in the code generated by simple code generator due to the following reasons: Code optimization enhances the portability of the compiler to the target processor. Code optimization allows consumption of fewer resources (i.e. CPU, Memory). Optimized code has faster execution speed.

Why is optimization important in programming?

The goal of optimization is to improve the behavior of a correct program so that it also meets customer needs for speed, throughput, memory footprint, power consumption, and so on. Optimization is thus as important to the development process as coding features is.

How do you make sure your code is optimized for performance?

Optimize Program Algorithm For any code, you should always allocate some time to think the right algorithm to use. So, the first task is to select and improve the algorithm which will be frequently used in the code. 2. Avoid Type Conversion Whenever possible, plan to use the same type of variables for processing.


1 Answers

Optimise your design and architecture - don't lock yourself into a design which will never scale - but don't micro-optimise your implementation. In particular, don't sacrifice simplicity and readability for micro-optimised implementation... at least not without benchmarking your code (ideally your whole system) first.

Measurement really is the key point when it comes to performance. Bottlenecks are almost never where you expect them to be. There are loads of different ways of measuring; optimisation without any measurement is futile IMO.

like image 74
Jon Skeet Avatar answered Sep 27 '22 23:09

Jon Skeet