DEV Community

Cover image for Benchmarking is harder than it looks
voctl
voctl

Posted on

Benchmarking is harder than it looks

I used to think benchmarking was fairly straightforward. Run a program, collect the numbers, change something, run it again. Compare the results.

That sounds reasonable until you actually start doing it.

While working on CPU inference benchmarks, I started paying much more attention to things I would normally ignore. CPU affinity, physical cores, SMT, warm-up runs, background activity. Even the order in which experiments are executed can matter. One thing I found interesting was the difference between using four physical cores and using two physical cores with SMT. I initially expected the results to be fairly obvious. They weren't. The four-core configuration performed better during prompt processing, while the two-core configuration with SMT was slightly faster during token generation. This made me reconsider how I was looking at benchmark results. Saying that one configuration is faster doesn't really mean much without specifying what workload you're measuring.Prompt processing and token generation are different workloads. Treating them as one performance metric hides some interesting behaviour.

There was also the problem of repeatability. A result from one run isn't particularly convincing. Even when the environment looks identical, measurements can vary. Warm-up behaviour and differences between experimental sessions can introduce effects that are easy to mistake for actual performance improvements. I ended up spending almost as much time checking the experimental setup as I spent running the benchmarks.

I don't think this is necessarily a bad thing. In fact, it is probably the most interesting part of doing performance research. You start by trying to measure a program, and eventually find yourself questioning whether your measurement actually represents what you think it represents.

I'm still working on improving the methodology and checking the results. But one thing has become clear to me: getting a number is easy. Understanding where that number came from is a different problem.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The split you found is the part worth keeping: four physical cores winning prompt processing while two cores with SMT edges token generation means a single "faster" verdict was never going to hold — the two phases are different workloads, so the honest headline has to carry both numbers, not one.

The line that stuck with me is that you spent almost as much time checking the setup as running the benchmarks. That is usually the tell that the measurement is the hard part, not the code. One concrete next step: run the same pair of configs in the reverse experiment order and see whether the token-generation edge survives the swap — if it flips with the order, it was warm-up or session drift, not the cores.

Which of the two results would you trust less right now — the prompt-processing win on four cores, or the token-generation edge on SMT — and what would you change first to make that one repeatable?