How not to optimize away - mechanics of a folly function
I was searching for a programming technique that would ensure variables used for benchmarking (without observable side effects) won't be optimized away by the compiler This gives some info, but I ended up using folly and the following function /** * Call doNotOptimizeAway(var) against variables that you use for * benchmarking but otherwise are useless. The compiler tends to do a * good job at eliminating unused variables, and this function fools * it into thinking var is in fact needed. */ #ifdef _MSC_VER #pragma optimize("", off) template <class T> void doNotOptimizeAway(T&& datum) { datum =