Benchmarking on Hyperthreaded CPUs

about | archive


[ 2006-December-05 22:24 ]

Be careful when benchmarking on a CPU with hyperthreading. Recently I made a small change which decreased performance by 16%. I was shocked because it should not have had that kind of impact. After some careful testing and experimentation, I discovered that running the test on another machine resulted in the performance I was expecting: a decrease of less than 1%.

The problem is that I was using the kernel's measurement of "user time" to measure the performance impact. This is not very accurate, but since my benchmark took a few minutes to run, it is accurate enough. It also has the nice property that if something else on my workstation runs for a moment, that time doesn't count against my benchmark. However, with hyperthreading that doesn't work. My process could be marked as "running," when in reality it is stalled inside the hyperthreaded CPU. I didn't investigate the issue as much as I would have liked, but hyperthreading can certainly be a strange beast.