Affiliate disclosure
Book titles on this page link to Amazon. As an Amazon Associate, DataField.Dev earns from qualifying purchases — at no additional cost to you.
Chapter 28 — Further Reading
Profiling and benchmarking sit at the meeting point of software craft and computer architecture. These resources deepen both — the discipline of measuring, and the hardware reasons behind what you measure — grouped by what you want from them.
The mindset: measure first
- Rob Pike, "Notes on Programming in C" (1989). The source of this chapter's epigraph and its whole thesis. Pike's rules 1–5 on optimization ("Measure. Don't tune for speed until you've measured…") are a page long and worth rereading yearly. Freely available online. (Tier 1.)
- Donald E. Knuth, "Structured Programming with
go toStatements," Computing Surveys 6(4), 1974. The origin of "premature optimization is the root of all evil" — read the full passage (the 97%/3% version), which is a far more balanced claim than the fragment usually quoted. (Tier 1.)
Why memory is usually the bottleneck
- John L. Hennessy and David A. Patterson, Computer Architecture: A Quantitative Approach (Morgan Kaufmann). The canonical text on caches, the memory hierarchy, and why a miss costs hundreds of cycles — the hardware behind "memory-bound." Chapters on memory hierarchy are the essential background. (Tier 1.)
- Ulrich Drepper, "What Every Programmer Should Know About Memory" (2007). A long, superb tutorial on how caches actually behave and how access patterns make or break performance — the deep version of §28.4. Free PDF. (Tier 1.)
- Samuel Williams, Andrew Waterman, and David Patterson, "Roofline: An Insightful Visual Performance Model for Multicore Architectures," Communications of the ACM 52(4), 2009. Introduces the roofline model that unifies memory- and compute-bound reasoning via arithmetic intensity — the picture behind §28.3, developed in the Chapter 38 capstone. (Tier 1.)
The tools
- The GNU
gprofmanual (sourceware.org/binutils/docs/gprof). The authoritative reference for the flat profile and call graph, including exactly how the sampling and the-pginstrumentation work and what their numbers mean. (Tier 1.) - The Valgrind / Cachegrind manual (
valgrind.org/docs/manual). How the cache simulation works, what theD1/LLdcounters mean, and how to drivecg_annotate. Read the caveats on the simulated (not measured) cache model. (Tier 1.) - The Linux
perfwiki (perf.wiki.kernel.org). The gateway to hardware performance counters —perf stat,perf record— for the "how much did it really cost on this CPU" measurements cachegrind cannot give. (Tier 1.) - Brendan Gregg, Systems Performance (Prentice Hall). The modern reference on performance methodology
and tools; excellent on how to measure without fooling yourself, and on
perfin depth. (Tier 1.) - Agner Fog's optimization manuals (
agner.org/optimize). Meticulous, empirical guides to how modern x86 microarchitectures behave — invaluable once you are optimizing the hot loop in Chapter 29. (Tier 2 — vendor-independent measurements, exceptionally careful but not a standard.)
Fortran specifics
- Milan Curcic, Modern Fortran: Building Efficient Parallel Applications (Manning, 2020). Times and
benchmarks real Fortran solvers in the modern style of this book, including
system_clockharnesses and the road to parallel speedups. The best Fortran-flavoured companion here. (Tier 1.) - Michael Metcalf, John Reid, and Malcolm Cohen, Modern Fortran Explained (Oxford). The precise
standard semantics of
system_clock,cpu_time, and the integer-kind resolution behaviour §28.1 depends on. Consult it when a timing subtlety must be exactly right. (Tier 1.) - The GCC / gfortran manual (
gcc.gnu.org/onlinedocs). The reference for-pg,-g,-fopt-info, and the optimization flags Chapter 30 will explore; also documents gfortran's high-resolution clock forint64arguments. (Tier 1.)
Suggested order
- Read Pike's rules (ten minutes) and the full Knuth passage — the mindset comes first.
- Skim the gprof manual's "Flat Profile" and "Call Graph" sections, then profile a program of your own.
- Read the Cachegrind manual's summary section and run it on the two stencil loop orders (Case Study 2).
- For the why, read Drepper (or the memory-hierarchy chapters of Hennessy & Patterson), then the Roofline paper for the unifying picture.
- Keep Gregg and Agner Fog on the shelf for when Chapter 29 turns diagnosis into optimization.