Write Fast Code Like a Native
summary
Walks through microbenchmarks using std::chrono, rdtsc/rdtscp and RDPMC, plus Godbolt and cycle counters, to build a latency intuition. Shows a naive matrix transpose costing ~250 ns (720 cycles) for tiny sizes and scaling to thousands of times slower when memory spills caches; a summation that the optimizer turns into a closed form (with O2 off it matches expected ~2,000,000 ns); XGBoost prediction costs ~60 assembly instructions per shallow tree (~0.1 ns per tree evaluation), and IO stays in millisecond land (disk spin ~8 ms, 10 Gb/s β 1 s/GB). Advises measure with RDPMC, avoid syscalls on the fast path, use templates for zero-overhead abstractions.
AI-written summary Β· about
chapters (11)
- 0:00Introduction and background
- 3:48Why write fast code
- 7:01Understanding CPU latencies
- 11:20Profiling tools and techniques
- 15:11Case study: Matrix transpose
- 22:42Case study: Summing numbers
- 27:42I/O and real-world operations
- 28:02Case study: XGBoost performance
- 33:19Code constructs and performance
- 39:58Philosophy of optimization
- 48:52Q&A session
related talks
01h 00mβWhen a Microsecond Is an Eternity: High Performance Trading Systems in C++β
01h 00mProgramming with less effort in C++...
49mWriting better code with help from Qt and the compiler
01h 02mFastware
40mLessons from two decades of writing bad code
01h 00mFastware
44mFastware
23mBeating the Benchmarks: Co-evolving the ISA and Development Tools
