2021-03-07, 01:13 PM
Optimisation is hard, but profiling is even harder. You can run micro-benchmarks like Marllun posted, but they are basically useless most of the time. The real trick is finding which parts of your code are actually slow, and for that you need the profiler plugin. Once you've narrowed down where the majority of the time is spent (don't try guess what is slow, because fast code called a lot is more important to optimise than slow code called infrequently) you can work on improving it. For that, the most important thing is algorithms - improve HOW the result is achieved, don't just try shave a few microseconds off the code. For example a poorly coded slow version of quicksort is still better than the most optimised version of bubblesort, because while the code itself may be worse, the algorithm is just so much better.