cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
command_line_parser.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 <cstddef>
23#include <stdexcept>
24#include <string>
25#include <vector>
26
27#include <lyra/args.hpp>
28#include <lyra/opt.hpp>
29#include <lyra/parser.hpp>
30
31namespace stat_bench {
32namespace runner {
33
35 cli_.add_argument(lyra::opt(config_.show_help)
36 .name("-h")
37 .name("--help")
38 .optional()
39 .help("Show this help."));
40
41 cli_.add_argument(lyra::opt(config_.plot_prefix, "prefix")
42 .name("--plot")
43 .optional()
44 .help("Generate plots of results."));
45
46 cli_.add_argument(lyra::opt(config_.json_file_path, "filepath")
47 .name("--json")
48 .optional()
49 .help("Generate JSON data file of results."));
50
51 cli_.add_argument(lyra::opt(config_.msgpack_file_path, "filepath")
52 .name("--msgpack")
53 .optional()
54 .help("Generate MsgPack data file of results."));
55
56 cli_.add_argument(
57 lyra::opt(config_.compressed_msgpack_file_path, "filepath")
58 .name("--compressed-msgpack")
59 .optional()
60 .help("Generate compressed MsgPack data file of results."));
61
62 cli_.add_argument(lyra::opt(config_.processing_time_samples, "num")
63 .name("--samples")
64 .optional()
65 .choices([](std::size_t val) { return val > 0; })
66 .help("Number of samples for measurements of processing time."));
67
68 cli_.add_argument(lyra::opt(config_.mean_processing_time_samples, "num")
69 .name("--mean_samples")
70 .optional()
71 .choices([](std::size_t val) { return val > 0; })
72 .help(
73 "Number of samples for measurements of mean processing time."));
74
75 cli_.add_argument(lyra::opt(config_.min_sample_duration_sec, "num")
76 .name("--min_sample_duration")
77 .optional()
78 .choices([](double val) { return val > 0.0; })
79 .help("Minimum duration of a sample for measurement "
80 "of mean processing time. [sec]"));
81
82 cli_.add_argument(lyra::opt(config_.min_warming_up_iterations, "num")
83 .name("--min_warming_up_iterations")
84 .optional()
85 .help("Minimum number of iterations for warming up."));
86
87 cli_.add_argument(lyra::opt(config_.min_warming_up_duration_sec, "num")
88 .name("--min_warming_up_duration_sec")
89 .optional()
90 .choices([](double val) { return val >= 0.0; })
91 .help("Minimum duration for warming up. [sec]"));
92
93 cli_.add_argument(lyra::opt(config_.include_glob, "pattern")
94 .name("--include")
95 .cardinality(0, 0)
96 .help("Specify glob patterns of benchmark names to include."
97 "When omitted, this option won't filter any benchmarks."));
98
99 cli_.add_argument(lyra::opt(config_.exclude_glob, "pattern")
100 .name("--exclude")
101 .cardinality(0, 0)
102 .help("Specify glob patterns of benchmark names to exclude."
103 "When omitted, this option won't filter any benchmarks."));
104
105 cli_.add_argument(lyra::opt(config_.include_regex, "regex")
106 .name("--include_regex")
107 .cardinality(0, 0)
108 .help("Specify regular expressions of benchmark names to include."
109 "When omitted, this option won't filter any benchmarks."));
110
111 cli_.add_argument(lyra::opt(config_.exclude_regex, "regex")
112 .name("--exclude_regex")
113 .cardinality(0, 0)
114 .help("Specify regular expressions of benchmark names to exclude."
115 "When omitted, this option won't filter any benchmarks."));
116}
117
119
120void CommandLineParser::parse_cli(int argc, const char** argv) {
121 const auto result = cli_.parse(lyra::args{argc, argv});
122 if (!result) {
123 throw std::runtime_error(result.message());
124 }
125}
126
127} // namespace runner
128} // namespace stat_bench
void parse_cli(int argc, const char **argv)
Parse command line arguments.
Definition of CommandLineParser class.
Namespace of classes to run benchmarks.
Namespace of stat_bench source codes.