I have seen too many people complaining about performance of their code before writing it over on different coding communities such as forums, Discord guilds, Slack etc. which results in them writing bad code or spending too much time on optimizing their software ever since they write the first line of code.
Computers are very fast, and machine time is less valueable than the limited time that You, as a human, have, whether it be Life, Deadlines or whatever else.
Before you worry about performance, write code! A piece of software that does nothing (or nothing productive) is the fastest!
Such as
int main() {
print("hello world!");
return 0;
}
This could run on my computer in 0.0000000001 seconds! Very fast, blazingly fast BUT it does nothing productive to make my life easier. The main objective of writing software is to make life easier by solving problems. Do you think of how much time you have wasted on worrying about performance? No, which is a bigger problem since you have a limited time to achieve tasks done within deadline.
Spend more time on writing code that does something, writing bad or hacky code is completely fine if you are prototyping features or attempting to figure out the best method to solve your problem. Once you have wrote the code, you can now worry about the performance since you have overcame the first obstacle. Benchmark your code, and any performance gain as small as 1% is a WIN!
- Don't assume speed, benchmark your code.
- Read and study about Big O Notations and different data structures on how you can overcome problems without recreating wheel.
- Don't optimize early, you are very likely to make big changes to your piece of code which is being prototyped or designed, which may be scrapped on a later date.
- Don't "overdo" optimization, sacrificing readable code is not always worth the speed.