cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
benchmark_case_registry.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 MusicScience37 (Kenta Kabashima)
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 */
21
22#include <utility>
23
27
28namespace stat_bench {
29namespace bench_impl {
30
31void BenchmarkCaseRegistry::add(std::shared_ptr<IBenchmarkCase> bench_case) {
32 const auto& group_name = bench_case->info().group_name();
33 auto& group = add_or_get_group(group_name);
34 group.add(std::move(bench_case));
35}
36
38 -> BenchmarkGroup& {
39 const auto [iter, inserted] = groups_.try_emplace(name, name);
40 return iter->second;
41}
42
44 for (auto iter = groups_.begin(); iter < groups_.end();) {
45 auto& group = iter->second;
46 group.filter_by(filter);
47 if (group.cases().empty()) {
48 iter = groups_.erase(iter);
49 } else {
50 ++iter;
51 }
52 }
53}
54
56 -> const util::OrderedMap<BenchmarkGroupName, BenchmarkGroup>& {
57 return groups_;
58}
59
61 static BenchmarkCaseRegistry registry;
62 return registry;
63}
64
65} // namespace bench_impl
66} // namespace stat_bench
Definition of BenchmarkCaseName class.
Definition of BenchmarkCaseRegistry class.
Definition of BenchmarkFullName class.
Definition of BenchmarkGroupName class.
Class of names of groups of benchmarks.
void filter_by(const filters::ComposedFilter &filter)
Filter.
void add(std::shared_ptr< IBenchmarkCase > bench_case)
Add a case.
static auto instance() -> BenchmarkCaseRegistry &
Get an instance of the registry.
auto benchmarks() const noexcept -> const util::OrderedMap< BenchmarkGroupName, BenchmarkGroup > &
Get benchmarks.
auto add_or_get_group(const BenchmarkGroupName &name) -> BenchmarkGroup &
Add a group if not exists, and return it.
Class of groups of cases in benchmarks.
Class of composed filters of benchmarks.
Namespace of internal implementation.
Namespace of utility functions and classes.
Namespace of stat_bench source codes.