cpp-simd-performancelisted
Install: claude install-skill rustcircle/c101
# C++ performance and SIMD
Loop: measure, profile, fix the top item, re-measure, keep only statistically clear wins. Build
exactly like production (`-O2`/`-O3`, same `-march`, LTO and PGO state) plus `-g
-fno-omit-frame-pointer`; Debug numbers are meaningless. Root-only machine tuning (governor,
turbo, `isolcpus`) is never done by the agent: list it as an Open doubt for the user.
Deep material: [profiling and compiler recipes](references/profiling-recipes.md) | [SIMD kernels and dispatch](references/simd-kernels.md)
## 1. Measurement discipline
```cpp
#include <benchmark/benchmark.h>
static void BM_Parse(benchmark::State& state) {
auto input = make_input(state.range(0));
for (auto _ : state) {
auto r = parse(input);
benchmark::DoNotOptimize(r); // non-const lvalue: the const& overload is deprecated
}
state.SetBytesProcessed(state.iterations() * static_cast<int64_t>(input.size()));
}
BENCHMARK(BM_Parse)->RangeMultiplier(8)->Range(64, 1 << 20)->Unit(benchmark::kMicrosecond);
BENCHMARK_MAIN();
```
`DoNotOptimize(x)` forces `x` to be materialized; `benchmark::ClobberMemory()` is a compiler
barrier that makes pending stores count as observed (use it after kernels that only write memory).
`state.PauseTiming()` / `ScopedPauseTiming` read the clock on every call, which swamps short
bodies: set up outside the loop or per batch. Aggregates include mean, median, stddev and CV.
```bash
./bench --benchmark_filter='BM_Parse/4096' --benchmark_rep