Optimising Serial Code
In this chapter, we will learn about optimising the code you write. Here, we will only talk about sequential performance, as we save the discussion of parallelising your code to later chapters. It is important to understand that when we talk about optimisation here, we are not talking about the use of the right algorithm. Here, we are entirely focused on the practical performance of our algorithms on specific hardware, not with the theoretical performance of an algorithm. This is a way of bringing back the constants from the Big O notation, which tell you the latency of the operations and the speed at which they perform. It is entirely possible that an algorithm outperforms an algorithm, if the system size is small enough. For this reason, we must take a practical view when talking about optimisation.
We will rely on benchmarks using the BenchmarkTools.jl
package to see performance differences. If you are unfamiliar on how to use this package, I suggest you go to the Measuring Performance chapter to learn this first.