Skip to content

Commit 30c8093

Browse files
committed
uniformize cxxopts syntax with bool args
1 parent 3c23255 commit 30c8093

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
build
22
build_debug
33
build_script
4+
.gdb_history
45
outputs
56
tags
67
compile_commands.json

benchmarks/benchmark.cpp

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <fast_float/fast_float.h>
2626
#include <fmt/core.h>
2727

28+
cxxopts::Options
29+
options("benchmark",
30+
"Compute the parsing speed of different number parsers.");
31+
2832
template <arithmetic_float T>
2933
void evaluateProperties(const std::vector<TestCase<T>> &lines,
3034
const std::vector<BenchArgs<T>> &args,
@@ -137,11 +141,6 @@ std::vector<TestCase<T>> get_random_numbers(size_t howmany,
137141
return lines;
138142
}
139143

140-
cxxopts::Options
141-
options("benchmark",
142-
"Compute the parsing speed of different number parsers.");
143-
144-
145144
// Checks if a floating-point number is exactly representable as the specified integer type
146145
template <std::integral int_type, std::floating_point float_type>
147146
bool is_exact_integer(float_type x) {
@@ -154,7 +153,7 @@ bool is_exact_integer(float_type x) {
154153

155154
// New template version of describe
156155
template <typename T>
157-
void describe(const std::variant<std::vector<TestCase<float>>, std::vector<TestCase<double>>> &numbers,
156+
void describe(const std::variant<std::vector<TestCase<float>>, std::vector<TestCase<double>>> &numbers,
158157
const std::vector<BenchArgs<T>> &args,
159158
const std::vector<std::string> &algo_filter) {
160159
std::visit([&args, &algo_filter](const auto &lines) {
@@ -286,34 +285,30 @@ int main(int argc, char **argv) {
286285
try {
287286
options.add_options()
288287
("f,file", "File name.",
289-
cxxopts::value<std::string>()->default_value(""))
288+
cxxopts::value<std::string>()->default_value(""))
290289
("F,fixed", "Fixed-point representation.",
291-
cxxopts::value<size_t>()->default_value("0"))
292-
("D,data", "Description of the data.")
290+
cxxopts::value<size_t>()->default_value("0"))
293291
("v,volume", "Volume (number of floats generated).",
294-
cxxopts::value<size_t>()->default_value("100000"))
292+
cxxopts::value<size_t>()->default_value("100000"))
295293
("m,model", "Random Model.",
296-
cxxopts::value<std::string>()->default_value("uniform_01"))
297-
("s,single", "Use single precision instead of double.",
298-
cxxopts::value<bool>()->default_value("false"))
299-
("S,string-eval", "Evaluate perf. of string generation from decimal mantissa/exponent",
300-
cxxopts::value<bool>()->default_value("false"))
301-
("t,test", "Test the algorithms and find their properties.",
302-
cxxopts::value<bool>()->default_value("false"))
303-
("e,errol", "Enable errol3 (current impl. returns invalid values, e.g., for 0).",
304-
cxxopts::value<bool>()->default_value("false"))
294+
cxxopts::value<std::string>()->default_value("uniform_01"))
305295
("a,algo-filter", "Filter algorithms by name substring: you can use multiple filters separated by commas.",
306-
cxxopts::value<std::vector<std::string>>())
296+
cxxopts::value<std::vector<std::string>>())
307297
("r,repeat", "Force a number of repetitions.",
308-
cxxopts::value<size_t>()->default_value("0"))
298+
cxxopts::value<size_t>()->default_value("0"))
299+
("D,data", "Description of the data.")
300+
("s,single", "Use single precision instead of double.")
301+
("S,string-eval", "Evaluate perf. of string generation from decimal mantissa/exponent")
302+
("t,test", "Test the algorithms and find their properties.")
303+
("e,errol", "Enable errol3 (current impl. returns invalid values, e.g., for 0).")
309304
("h,help", "Print usage.");
310305
const auto result = options.parse(argc, argv);
311306

312-
if (result["help"].as<bool>()) {
307+
if (result.count("help") > 0) {
313308
fmt::print("{}\n", options.help());
314309
return EXIT_SUCCESS;
315310
}
316-
const bool single = result["single"].as<bool>();
311+
const bool single = result.count("single") > 0;
317312
const auto filter = result.count("algo-filter")
318313
? result["algo-filter"].as<std::vector<std::string>>()
319314
: std::vector<std::string>{};
@@ -340,22 +335,23 @@ int main(int argc, char **argv) {
340335
}
341336

342337
std::variant<std::vector<BenchArgs<float>>, std::vector<BenchArgs<double>>> algorithms;
343-
const bool errol = result["errol"].as<bool>();
338+
const bool errol = result.count("errol") > 0;
344339
const size_t repeat = result["repeat"].as<size_t>();
345340
const size_t fixed_size = result["fixed"].as<size_t>();
346341
if (single)
347342
algorithms = initArgs<float>(errol, repeat, fixed_size);
348343
else
349344
algorithms = initArgs<double>(errol, repeat, fixed_size);
350-
if (result["data"].as<bool>()) {
345+
if (result.count("data") > 0) {
351346
if (single)
352347
describe<float>(numbers, std::get<std::vector<BenchArgs<float>>>(algorithms), filter);
353348
else
354349
describe<double>(numbers, std::get<std::vector<BenchArgs<double>>>(algorithms), filter);
355350
return EXIT_SUCCESS;
356351
}
357-
const bool test = result["test"].as<bool>();
358-
const bool string_eval = result["string-eval"].as<bool>();
352+
353+
const bool test = result.count("test") > 0;
354+
const bool string_eval = result.count("string-eval") > 0;
359355
std::visit([test, string_eval, &filter](const auto &lines, const auto &args) {
360356
using T1 = typename std::decay_t<decltype(lines)>::value_type::Type;
361357
using T2 = typename std::decay_t<decltype(args)>::value_type::Type;

0 commit comments

Comments
 (0)