Skip to Content
Hands-On Design Patterns with C++
book

Hands-On Design Patterns with C++

by Fedor G. Pikus
January 2019
Intermediate to advanced
512 pages
14h 5m
English
Packt Publishing
Content preview from Hands-On Design Patterns with C++

Effect of local buffer optimization

How much faster is the small_string compared to the simple_string? That depends, of course, on what you need to do with it. Let's start with just creating and deleting the strings. To avoid typing the same benchmark code twice, we can use the template benchmark, as follows:

template <typename T>void BM_string_create_short(benchmark::State& state) {    const char* s = "Simple string";    for (auto _ : state) {        REPEAT({ T S(s); benchmark::DoNotOptimize(S); })    }    state.SetItemsProcessed(32*state.iterations());}BENCHMARK_TEMPLATE1(BM_string_create_short, simple_string);BENCHMARK_TEMPLATE1(BM_string_create_short, small_string);

The result is quite impressive:

It gets even better when we try the same test on multiple ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Structural Design Patterns in Modern C++

Structural Design Patterns in Modern C++

Umar Lone

Publisher Resources

ISBN: 9781788832564Supplemental Content