January 2019
Intermediate to advanced
512 pages
14h 5m
English
Every benchmark needs a baseline. In our case, the baseline is a raw pointer. We can reasonably assume that no smart pointer will be able to outperform a raw pointer, and the best smart pointer will have zero overhead. Thus, we begin by measuring how long it takes to construct and destroy a small object using a raw pointer:
struct deleter { template <typename T> void operator()(T* p) { delete p; }};void BM_rawptr(benchmark::State& state) { deleter d; for (auto _ : state) { int* p = new int(0); d(p); } state.SetItemsProcessed(state.iterations());}
The actual numbers reported by the benchmark depend, of course, on the machine that it runs on. But we are interested in the relative changes, so any machine will do, ...
Read now
Unlock full access