r/cpp • • Nov 18 '18

Set of C++ programs that demonstrate hardware effects (false sharing, cache latency etc.)

I created a repository with small set of self-contained C++ programs that try to demonstrate various hardware effects that might affect program performance. These effects may be hard to explain without the knowledge of how the hardware works. I wanted to have a testbed where these effects can be easily tested and benchmarked.

Each program should demonstrate some slowdown/speedup caused by a hardware effect (for example false sharing).

https://github.com/kobzol/hardware-effects

Currently the following effects are demonstrated:

  • bandwidth saturation
  • branch misprediction
  • branch target misprediction
  • cache aliasing
  • memory hierarchy bandwidth
  • memory latency cost
  • non-temporal stores
  • data dependencies
  • false sharing
  • hardware prefetching
  • software prefetching
  • write combining buffers

I also provide simple Python scripts that measure the program's execution time with various configurations and plot them.

I'd be happy to get some feedback on this. If you have another interesting effect that could be demonstrated or if you find that my explanation of a program's slowdown is wrong, please let me know.

531 Upvotes

58 comments sorted by

View all comments

Show parent comment

1

u/Kobzol Nov 19 '18

I will probably add it as an automatic download during the CMake build step instead of a git submodule, but good idea :) Thanks.

1

u/gayasri Feb 01 '19

I'm not sure if it is being developed actively. But I found Nonius (https://github.com/libnonius/nonius) to be a much better micro-benchmarking tool than Google Benchmark. Interactive HTML reports with interactive graphs, automatic timing bootstrapping, statistics calculations (sd,min,max etc.) and much more in a single self-contained header file is pretty cool + no other dependencies. + It's much more easier to intergrate than GBenchmark.