3 ms·
I read something, somewhere, a while back that really stuck with me. > It is impossible to make your code faster, you can only make it do less. The only way to
by redbeard0x0a 10y ago
I read something, somewhere, a while back that really stuck with me.
> It is impossible to make your code faster, you can only make it do less. The only way to 'speed-up' a process is to achieve the same result with less code (or really, less cpu cycles).
This is along the lines of less is more, but it is also something that really helped drive home the need to reduce, refactor and refine code instead of just piling more code on top of what you already have.
- jve 10y agoYour quote makes me feel like you are targeting code lines/chars. Less cpu cycles != less lines of code. For example, bubble sort would be little more than 10 lines where merge sort would be twice as that.
- redbeard0x0a 10y agoWhat I was really trying to express is the fact that you cannot make code run faster (on the same machine), but this is something we all say - we made xyz faster. Every line of code you write has a price, both in performance and in security/bugs. Security issues and bugs typically are tied to lines of code, but performance is definitely not. To really understand this, you have to understand how machines work. Merge sort is faster because the processor does less work for the same input compared to the bubble sort. How many lines of code you have is rarely a good mapping of how much work your processor is doing. You have to take into account the complexity (i.e. O(n) or O(N^2)), the framework your are using (just because you have 3 lines of code in a Rails controller, doesn't mean you are executing 3 lines of code, etc.