reactivemarkets / toolbox-cpp

The Reactive C++ Toolbox is an open source library of C++20 components designed for efficient, asynchronous network applications on the Linux platform.
https://reactivemarkets.github.io/toolbox-cpp/
Other
21 stars 20 forks source link

Feature/unformated logging benchmark #118

Closed rfernandes closed 3 years ago

rfernandes commented 3 years ago

Not calling, flag / setting reset on every log line yields significant performance benefits. This does mean that changes to io fields (width, spacing, good, etc) will persist across log calls, and that it's now the responsibility of the caller to restore whatever modifiers are set. OStringStream reuse is now somewhat similar to the stringstream reuse idiom:

stringstream ss;
(...)
ss.str("");
ss.clear();

with

OStaticStream<7> os;
(...)
os.reset()
os.clear()

Benchmark results (Before/After):

NAME COUNT MIN %50 %95 %99 %99.9 %99.99
log_formated 95225000 0.03 0.03 0.032 0.032 0.036 0.041
log_unformated 96840000 0.028 0.03 0.031 0.032 0.042 0.043
NAME COUNT MIN %50 %95 %99 %99.9 %99.99
log_formated 167730000 0.017 0.017 0.018 0.018 0.02 0.02
log_unformated 170380000 0.017 0.017 0.017 0.018 0.019 0.02