I'm currently in the process of benchmarking my database library and have provided a sample code snippet for reference.
BENCHMARK_DEFINE_F(ISqlConnectionBenchmark, benchmarkConnectionConstruction)(benchmark::State& state) {
for (auto _ : state) {
auto connection = ISqlConnectionBenchmark::createConnection();
::benchmark::DoNotOptimize(connection.get());
// Skip measuring connection destruction
connection.reset();
connection = nullptr;
::benchmark::ClobberMemory();
}
}
BENCHMARK_REGISTER_F(ISqlConnectionBenchmark, benchmarkConnectionConstruction);
To prevent optimization, I've employed the use of DoNotOptimize and ClobberMemory techniques. However, a team member has suggested that we should halt the timer before invoking the ClobberMemory function. This suggestion seems reasonable, especially if the ClobberMemory function is transformed into assembly code that effectively flushes all cache lines. I've conducted research on various examples and CPPCon presentations, but none have demonstrated such a practice.
Is there any relevant information or insight that I might be overlooking?
Regards,
Abhi Arora