2727
2828using Benchmarks::BenchArgs;
2929
30- bool is_matched (const std::string &str, const std::span<std::string> filter) {
31- if (filter.empty ()) {
32- return true ;
33- }
34- for (const auto &f : filter) {
35- if (str.find (f) != std::string::npos) {
36- return true ;
37- }
38- }
39- return false ;
40- }
41-
4230template <arithmetic_float T>
4331void evaluateProperties (const std::vector<T> &lines,
4432 const std::array<BenchArgs<T>, Benchmarks::COUNT> &args,
45- const std::span <std::string> filter = {} ) {
33+ const std::vector <std::string> &algo_filter ) {
4634 fmt::println (" {:20} {:20}" , " Algorithm" , " Valid round-trip" );
4735
4836 for (const auto &algo : args) {
4937 if (!algo.used ) {
5038 fmt::println (" # skipping {}" , algo.name );
5139 continue ;
5240 }
53- // Apply filter if provided
54- if (!is_matched (algo.name , filter)) {
41+ if (algo_filtered_out (algo.name , algo_filter)) {
5542 fmt::println (" # filtered out {}" , algo.name );
5643 continue ;
5744 }
45+
5846 char buf1[100 ], buf2[100 ];
5947 std::span<char > bufRef (buf1, sizeof (buf1)), bufAlgo (buf2, sizeof (buf2));
6048 int incorrect = 0 ;
@@ -94,10 +82,11 @@ struct diy_float_t {
9482
9583template <arithmetic_float T>
9684void process (const std::vector<T> &lines,
97- const std::array<BenchArgs<T>, Benchmarks::COUNT> &args, const std::span<std::string> filter = {}) {
85+ const std::array<BenchArgs<T>, Benchmarks::COUNT> &args,
86+ const std::vector<std::string> &algo_filter) {
9887 // We have a special algorithm for the string generation:
99- std::string just_string = " just_string" ;
100- if ( is_matched ( just_string, filter )) {
88+ if ( const std::string just_string = " just_string" ;
89+ ! algo_filtered_out ( just_string, algo_filter )) {
10190 std::vector<diy_float_t > parsed;
10291 for (auto d : lines) {
10392 auto v = jkj::grisu_exact (d);
@@ -114,16 +103,17 @@ void process(const std::vector<T> &lines,
114103 } else {
115104 fmt::println (" # skipping {}" , just_string);
116105 }
106+
117107 for (const auto &algo : args) {
118108 if (!algo.used ) {
119109 fmt::println (" # skipping {}" , algo.name );
120110 continue ;
121111 }
122- // Apply filter if provided
123- if (!is_matched (algo.name , filter)) {
112+ if (algo_filtered_out (algo.name , algo_filter)) {
124113 fmt::println (" # filtered out {}" , algo.name );
125114 continue ;
126115 }
116+
127117 pretty_print (lines, algo.name , [&algo](const std::vector<T> &lines) -> int {
128118 int volume = 0 ;
129119 char buf[100 ];
@@ -133,14 +123,13 @@ void process(const std::vector<T> &lines,
133123 return volume;
134124 }, algo.testRepeat );
135125 }
136-
137126}
138127
139128template <typename T>
140129std::vector<T> fileload (const std::string &filename) {
141130 std::ifstream inputfile (filename);
142131 if (!inputfile) {
143- fmt::print (stderr, " can't open {}\n " , filename);
132+ fmt::println (stderr, " can't open {}" , filename);
144133 return {};
145134 }
146135
@@ -151,7 +140,7 @@ std::vector<T> fileload(const std::string &filename) {
151140 lines.push_back (std::is_same_v<T, float > ? std::stof (line)
152141 : std::stod (line));
153142 } catch (...) {
154- fmt::print (stderr, " problem with {}\n We expect floating-point numbers (one per line).\n " , line);
143+ fmt::println (stderr, " problem with {}\n We expect floating-point numbers (one per line)." , line);
155144 std::abort ();
156145 }
157146 }
@@ -165,7 +154,7 @@ std::vector<T> get_random_numbers(size_t howmany,
165154 fmt::println (" # parsing random numbers" );
166155 std::vector<T> lines;
167156 auto g = get_generator_by_name<T>(random_model);
168- fmt::print (" model: {}\n volume: {} floats\n " , g->describe (), howmany);
157+ fmt::println (" model: {}\n volume: {} floats" , g->describe (), howmany);
169158 lines.reserve (howmany); // let us reserve plenty of memory.
170159 for (size_t i = 0 ; i < howmany; i++) {
171160 const T line = g->new_float ();
@@ -218,7 +207,8 @@ int main(int argc, char **argv) {
218207 numbers = get_random_numbers<float >(volume, model);
219208 else
220209 numbers = get_random_numbers<double >(volume, model);
221- fmt::println (" # You can also provide a filename (with the -f flag): it should contain one string per line corresponding to a number" );
210+ fmt::println (" # You can also provide a filename (with the -f flag):"
211+ " it should contain one string per line corresponding to a number" );
222212 }
223213 else {
224214 if (single)
0 commit comments