# Tuning a Server for Benchmarking

DevFeed: [Tuning a Server for Benchmarking](<https://devfeed.tech/articles/tuning-a-server-for-benchmarking-60982.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/tuning-a-server-for-benchmarking/>)

Author: David Álvarez Rosa

Published: 2026-06-25T17:02:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [rapidfireai](<https://devfeed.tech/topics/rapidfireai.md>), [Macrobenchmark](<https://devfeed.tech/topics/macrobenchmark.md>), [NUMA](<https://devfeed.tech/topics/numa.md>), [Processor Affinity](<https://devfeed.tech/topics/processor-affinity.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [hardware](<https://devfeed.tech/tags/hardware.md>), [performance](<https://devfeed.tech/tags/performance.md>), [time](<https://devfeed.tech/tags/time.md>)

## AI overview

The article demonstrates how to reduce noise in microbenchmarks by tuning a server, including pinning the benchmark to a core and locking CPU frequency. It reports that core pinning lowered the measured mean to 55.3 µs and reduced the coefficient of variation to 1.06%.

## Source excerpt

Optimizing code starts with measuring it, and a measurement is only useful if it is repeatable: a 2% improvement is invisible under 5% of noise. Yet on an untuned machine the same binary can easily run several percent faster or slower between runs. In this post we take a tiny benchmark and tune the machine step by step, re-measuring after every change, until runs become deterministic.1 A noisy baseline § Our running example sums an array of doubles, in short bursts. Real services rarely hammer the CPU continuously: they handle a request, sit idle, and wake up for the next one. Each timed iteration here runs a burst of 256 sums after a 2 ms idle gap, with the gap excluded from the measurement2 static auto BM_Sum(benchmark::State& state) -> void { alignas(64) static std::array<double, 4096> data; std::iota(data.begin(), data.end(), 0.0); for (auto _ : state) { state.PauseTiming(); // Idle between bursts, like a real service std::this_thread::sleep_for(std::chrono::milliseconds(2)); state.ResumeTiming(); for (auto i = 0; i < 256; ++i) { auto sum = std::accumulate(data.cbegin(), data.cend(), 0.0); benchmark::DoNotOptimize(sum); } } } BENCHMARK(BM_Sum); Compile it in release with all optimizations, -O3, and -march=native -mtune=native -flto -ffast-math. Then run ten repetitions and aggregate them $ ./benchmark --benchmark_repetitions=10 --benchmark_min_time=100x BM_Sum_mean 99575 ns BM_Sum_stddev 2704 ns BM_Sum_cv 2.72 % The interesting line is cv, the coefficient of variation: standard deviation divided by mean. Almost 3% of run-to-run noise--any optimization smaller than that is invisible. Let's bring it down. Know your hardware § Before turning any knob, look at what you are tuning. lstopo draws the whole machine in one picture: caches, cores, SMT pairs, and the PCIe devices hanging off them. Start with my laptop Figure 1: My laptop (Intel Core Ultra 5 135U). Three kinds of cores: two P-cores with two hardware threads each (dotted), eight E-cores in clusters of four sh