Performance Tuning and Benchmarking in Go
About the book
Have you ever wondered how to determine if your Go code is performing at its best?
This book is a hands-on introduction to writing and running benchmarking tests in Go. Start with the fundamentals. Then build on what you learn and create more complex benchmarks. Finally, compare test results and run benchmarks with GitHub Actions.
You can't improve code without measuring its behavior and resource use. This book sets you on the journey to learn how to make informed decisions when writing Go code.
What you will learn
By reading through the book and completing the exercises, you will learn:
How to write benchmarking tests from scratch
How to convert your regular tests into benchmarks
How to interpret benchmarking results
How to structure table-driven benchmarks
How to run benchmarks in parallel
How to avoid common mistakes
How to compare benchmarks
How to speed up code and reduce memory use by choosing the right data structures and algorithms
How to run benchmarking as a part of CI pipelines using GitHub Action
By mastering these skills, you will improve your understanding of the code. It will help you decide if your project requires refactoring. And if you or your team are making effective use of engineering time. With data on how and why to improve the code, you'll be better able to make a business case for a change request.
You will learn if and why chasing nanoseconds wastes engineering time in some cases. Knowing trade-offs and making informed decisions will make you a better engineer.
Table of Contents
Introduction to benchmarking
Using the Go test tool
Benchmarking internals
Structuring benchmarks
Managing the benchmark timer
Cleaning up after benchmarks
Running table-driven benchmarks
Running benchmarks in parallel
Ensuring benchmarks accuracy
Comparing benchmarks
Running benchmarks in CI pipelines