In theory, you can compare the actual-time speeds of two algorithms by running the code on your computer and using a stopwatch to see how long each algorithm takes. This is the essence of what benchmarking is, except that benchmarking is a lot more practical. Besides being tedious, using a stopwatch to measure the speed of code is error-prone. Also, what if the two algorithms both run in less than one second? You’d better have fast thumbs.
Thankfully, you can use benchmarking software to measure the time for you. The software tracks the precise time your code starts running and when it finishes. The benchmarking tool then tells you exactly how much time your code took to run.
So, there’s nothing fancy about benchmarking; it’s basically the computer running a stopwatch for you. However, it does come with a big bonus: it measures time very precisely, down to the microsecond. (A microsecond is one-millionth of a second.)
Before we move on, I can’t emphasize enough that for the duration of this chapter, we will not be measuring speed in terms of the number of steps at all. When it comes to benchmarking, we’ll always be measuring the actual time of an algorithm.