Chapter 8. Benchmarking

Hopefully, your Go IDE is ready and warmed up for some action! It’s time to stress our Go code to find its efficiency characteristics on the micro and macro levels mentioned in Chapter 7.

In this chapter, we will start with “Microbenchmarks”, where we will go through the basics of microbenchmarking and introduce Go native benchmarking. Next, I will explain how to interpret the output with tools like benchstat. Then I will go through the microbenchmark aspects and tricks that I learned that are incredibly useful for the practical use of microbenchmarks.

In the second half of this chapter, we’ll go through “Macrobenchmarks”, which is rarely in the scope of programming books due to its size and complexity. In my opinion, macrobenchmarking is as critical to Go development as microbenchmarking, so every developer caring about efficiency should be able to work with that level of testing. Next, in “Go e2e Framework” we will go through a complete example of a macro test written fully in Go using containers. We will discuss results and common observability in the process.

Without further ado, let’s jump into the most agile way of assessing the efficiency of smaller parts of the code, namely microbenchmarking.

Microbenchmarks

A benchmark can be called a microbenchmark if it’s focused on a single, isolated functionality on a small piece of code running in a single process. You can think of microbenchmarks as a tool for efficiency assessment of optimizations made ...

Get Efficient Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.