Clean Code & Performance
What is the impact of Clean Code on Software Performance?
Design Patterns
Design patterns impact on energy efficiency
๐ References
"Clean" Code, Horrible Performance - by Casey Muratori
When we look at the results, we see something rather remarkable: just that one change โ writing the code the old fashioned way rather than the โcleanโ code way โ gave us an immediate 1.5x performance increase. Thatโs a free 1.5x for not doing anything other than removing the extraneous stuff required to use C++ polymorphism.
The ideas underlying the โcleanโ code methodology are almost all horrible for performance, and you shouldnโt do them.
While the
forEach
method is less verbose and looks cleaner, it's generally slower than the traditionalfor
loop due to the extra function call overhead for each iteration.
Set.has
is more performant than Array.includes
if we need to search a dataset multiple times, a better option would be to create an index
you can often make a program faster by using more memory (space)
----------------------
Time taken for fibonacciRecursive with input 35: 89.2701244354248 milliseconds
----------------------
Time taken for fibonacciMemoization with input 35: 0.028415679931640625 milliseconds
----------------------
Time taken for fibonacciIterative with input 35: 0.01462554931640625 milliseconds
----------------------
Time taken for fibonacciMemoization with input 1000: 0.17408275604248047 milliseconds
----------------------
Time taken for fibonacciIterative with input 1000: 0.13091564178466797 milliseconds
- Write code thatโs easy to understand first. Maintainability matters.
- Measure performance and optimize only where it makes a real difference. Avoid early optimization for complex problems that donโt need it.
- Get comfortable with Big O notation โ itโll guide your decisions about time and space efficiency.
- Balance is key. Too much optimization can make code hard to read, while overly concise code can suffer in performance.