Profiling and Optimisation
Write a program in any language.
Use a profiler to identify the sections of code which have the most time spent in them, or to identify objects most frequently interacted with.
Consider how to reduce the amount of time being spent there:
- change the algorithm to something that uses less brute force
- change the algorithm to trade memory for speed. (using caches, etc...)
- change the algorithm to take advantage of the many processors cores, or even offload to a specialist circuit such as the gpu, or fpga.
- change the data structure to align it the cpu cache line and size.
- change the data structure to remove unused space
- by using smaller fields,
- by packing the struct more suitable,
- by using nan tagging and pointer tagging techniques.
- change the language to something with few layers of interpretation between what you write and what is executed. (for c this would be assembly)
- This avoids many compilers/jits/interpreters but also avoids the tricks inside them to squeeze out performance, and tends to sacrifice portability across machines.
- If you do go with assembly for a given optimisation, always have a non-assembly version of this code available to baseline against and for portability.
- Similar advice goes for offloading to the gpu/fpga, keep a cpu version for baselining/portability (not every machine has a gpu/fpga).
Ensure that you run the program before and after each alteration to ensure that speed is improving in the section you are considering.
Rinse and repeat.