cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
benchmark_group.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
24#include <fmt/format.h>
25
29
30namespace stat_bench {
31namespace bench_impl {
32
35
36auto BenchmarkGroup::name() const noexcept -> const BenchmarkGroupName& {
37 return name_;
38}
39
40void BenchmarkGroup::add(std::shared_ptr<IBenchmarkCase> bench_case) {
41 if (bench_case->info().group_name() != name_) {
43 fmt::format("Different name of benchmark group to add (Expected: "
44 "{}, Actual: {}).",
45 name_, bench_case->info().group_name()));
46 }
47
48 const auto& case_name = bench_case->info().case_name();
49 const auto [iter, inserted] = cases_.try_emplace(case_name, bench_case);
50 if (!inserted) {
52 fmt::format("Duplicate benchmark name {}.", bench_case->info()));
53 }
54}
55
57 for (auto iter = cases_.begin(); iter < cases_.end();) {
58 if (filter.check((*iter->second).info())) {
59 ++iter;
60 } else {
61 iter = cases_.erase(iter);
62 }
63 }
64}
65
66auto BenchmarkGroup::cases() const noexcept -> const
67 util::OrderedMap<BenchmarkCaseName, std::shared_ptr<IBenchmarkCase>>& {
68 return cases_;
69}
70
72 return config_;
73}
74
75auto BenchmarkGroup::config() const noexcept -> const BenchmarkGroupConfig& {
76 return config_;
77}
78
79} // namespace bench_impl
80} // namespace stat_bench
Definition of BenchmarkCaseName class.
Definition of BenchmarkFullName class.
Definition of BenchmarkGroup class.
Class of names of cases of benchmarks.
Class of names of groups of benchmarks.
Class of exceptions in this library.
Class of configuration of a group of cases in benchmarks.
auto config() noexcept -> BenchmarkGroupConfig &
Get the configuration.
void add(std::shared_ptr< IBenchmarkCase > bench_case)
Add a case.
auto name() const noexcept -> const BenchmarkGroupName &
Get the group name.
void filter_by(const filters::ComposedFilter &filter)
Filter.
auto cases() const noexcept -> const util::OrderedMap< BenchmarkCaseName, std::shared_ptr< IBenchmarkCase > > &
Get cases.
BenchmarkGroup(BenchmarkGroupName name)
Constructor.
Interface of cases in benchmarks.
Class of composed filters of benchmarks.
auto check(const BenchmarkFullName &name) const -> bool
Check whether a name matches to this filter.
Namespace of internal implementation.
Namespace of utility functions and classes.
Namespace of stat_bench source codes.
STL namespace.
Definition of StatBenchException class.