Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Suite.hpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2021 Reactive Markets Limited
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#ifndef TOOLBOX_BM_SUITE_HPP
17#define TOOLBOX_BM_SUITE_HPP
18
20
22
23namespace toolbox::bm {
24
26 public:
27 explicit BenchmarkSuite(std::ostream& os, double value_scale = 1.0);
28
29 template <typename FnT>
30 void run(const char* name, FnT fn)
31 {
32 using namespace std::literals::chrono_literals;
33 constexpr auto duration = 3s;
34
35 Histogram hist{1, 1'000'000'000, 5};
36 Context ctx{hist};
37 Alarm alarm{duration, [&ctx]() { ctx.stop(); }};
38 fn(ctx);
39 report(name, hist);
40 }
41 void report(const char* name, Histogram& hist);
42
43 private:
44 std::ostream& os_;
45 double value_scale_;
46};
47
48} // namespace toolbox::bm
49
50#endif // TOOLBOX_BM_SUITE_HPP
#define TOOLBOX_API
Definition Config.h:39
void run(const char *name, FnT fn)
Definition Suite.hpp:30
A High Dynamic Range (HDR) Histogram.
Definition Histogram.hpp:64