The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Profiling with perf and Top-Down Microarchitecture Analysis to Build Benchmarks That Don’t Lie
A hash function benchmarked at four times faster ships, and the service doesn’t move, because the compiler deleted the work being measured. Most C++ performance work fails like this: confident numbers, wrong conclusions. Bare-Metal Performance Engineering in C++ follows one real request-handling service from 50,000 cycles per request down to about a quarter of that, showing every measurement, every bottleneck, and every fix along the way.
With Membership
Free!
$39.99
About the Book
Your benchmark says 4x faster and production doesn’t move. This book is about why, and how to make your numbers tell the truth.
Most C++ performance advice is folklore: virtual calls are slow, exceptions are free, -O3 beats -O2, more threads means more throughput. Each of these is true on some hardware, for some workloads, some of the time, and teams lose weeks acting on them without measuring. Meanwhile the real costs go unseen: a compiler that quietly deleted the code being benchmarked, a profiler that blamed the instruction after the one that missed cache, a hash table that waits on DRAM twice per lookup, a load test that misses the stalls production clients hit.
Bare-Metal Performance Engineering in C++ teaches the discipline that replaces guesswork with evidence. You’ll learn to write benchmarks the compiler can’t fool, to read hardware counters without being misled by multiplexing or skid, and to use Top-Down Microarchitecture Analysis to find in one run whether code is starved in the front end, losing work to mispredictions, or stalled on memory. Then you’ll apply that method from the compiler out to the kernel, and keep the results in place in production.
The book follows a single realistic workload from start to finish: a request-handling service that parses JSON, looks keys up in a multi-million-entry hash table, and serializes responses. Every chapter ends with a Bottleneck Ledger entry recording the service’s cycles per request, IPC, cache misses, and latency percentiles, the dominant bottleneck at that stage, what changed, and how the change was verified. By the end, the service uses about a third to a quarter of the CPU per request it started with, with a fraction of its original tail latency, and every step of that improvement is shown and justified.
What you’ll learnperf stat, perf record, precise events, call graphs, flame graphs, and differential profiles correctlystd::function, and template bloatThis book is for C++ engineers who own the performance of code that runs in production: backend and infrastructure engineers with latency objectives, library maintainers, low-latency and trading developers, and anyone who reviews pull requests that claim speedups. It assumes you’re comfortable with modern C++ and basic computer architecture terms like caches and pipelines. It doesn’t assume prior experience with perf, assembly, or Top-Down analysis, because each tool is introduced from first principles where it’s needed.
It isn’t an algorithms book. It covers what happens after you’ve chosen the right algorithm, when two implementations of it differ by a factor of five because of how they use the machine.
What makes it differentVTune, AMD uProf, bpftrace, and Perfetto are used in later chapters. Four appendices give quick references for perf, hardware events and Top-Down metrics, compiler flags, and a full benchmarking and profiling checklist.
About the Author
Weston Ashgrove is a C++ systems engineer who builds software where being wrong or slow has a cost. He came up through quantitative trading, building order books, matching logic and the low-latency infrastructure underneath them and now brings the same discipline to performance engineering, concurrency, storage, networking, GPUs, and AI inference.
His rule for performance-critical code is simple: nothing is true until it has been profiled, fuzzed, and replayed. Every technique in his books comes with the measurement that proves it, the trade-off it costs, and the failure it prevents. He writes for working engineers who ship and debug production C++, and he leaves out anything that only works on a slide.
You can get the free Community Edition in PDF or EPUB just by sharing your name and email address with the author.
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
Learn more about writing on Leanpub
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.