2 ms·
Indeed, the ways to write efficient code are driven by testing and measuring rather than trying to write code that is efficient (probably with silly micro-optim
by dan-robertson 6y ago
Indeed, the ways to write efficient code are driven by testing and measuring rather than trying to write code that is efficient (probably with silly micro-optimisations) from the start. The importance of readability to efficiency is that it would be good for your code to be obviously linear (or n log n) from reading it.
The most significant efficiency improvements typically come from better algorithms or data structures in specific cases. Sometimes improvements to heuristics too. Lesser improvements may come from optimising hot code (eg making it better for the cache) or fundamental language changes (e.g. in a more statically typed language, field accesses may be pointer dereferences, or even better pointer addition, rather than hashtable lookups. But languages like python probably have better tuned general-purpose hashtable implementations than you’ll likely find elsewhere. Also changing default data structures from e.g. linked lists and binary trees to arrays (or something array like) and b-trees (or some other shallow tree) will likely be good)