|
6 | 6 | #include <sourcemeta/blaze/evaluator.h>
|
7 | 7 |
|
8 | 8 | #include <chrono> // std::chrono
|
| 9 | +#include <cmath> // for sqrt |
9 | 10 | #include <cstdlib> // EXIT_SUCCESS, EXIT_FAILURE
|
10 | 11 | #include <iostream> // std::cerr
|
11 | 12 | #include <set> // std::set
|
12 | 13 | #include <string> // std::string
|
13 |
| -#include <cmath> // for sqrt |
14 | 14 |
|
15 | 15 | #include "command.h"
|
16 | 16 | #include "utils.h"
|
17 | 17 |
|
18 | 18 | // parse unsigned int option, how many loop for benchmarking
|
19 | 19 | auto benchmark_loop(
|
20 |
| - const std::map<std::string, std::vector<std::string>> &options) |
21 |
| - -> size_t { |
| 20 | + const std::map<std::string, std::vector<std::string>> &options) -> size_t { |
22 | 21 |
|
23 | 22 | size_t loop = 1;
|
24 | 23 |
|
@@ -142,9 +141,8 @@ auto sourcemeta::jsonschema::cli::validate(
|
142 | 141 | } else if (subresult) {
|
143 | 142 | log_verbose(options)
|
144 | 143 | << "ok: " << safe_weakly_canonical(instance_path).string()
|
145 |
| - << " (entry #" << index << ")" |
146 |
| - << "\n matches " << safe_weakly_canonical(schema_path).string() |
147 |
| - << "\n"; |
| 144 | + << " (entry #" << index << ")" << "\n matches " |
| 145 | + << safe_weakly_canonical(schema_path).string() << "\n"; |
148 | 146 | print_annotations(output, options, std::cerr);
|
149 | 147 | } else {
|
150 | 148 | std::cerr << "fail: "
|
@@ -179,38 +177,45 @@ auto sourcemeta::jsonschema::cli::validate(
|
179 | 177 | double sum = 0.0, sum2 = 0.0, empty = 0.0;
|
180 | 178 | size_t count = 0;
|
181 | 179 |
|
182 |
| - // overhead evaluation, if the compiler is kind enough not to optimize this out! |
183 |
| - for (auto i = bench_loop; i; i--) { |
| 180 | + // overhead evaluation, if the compiler is kind enough not to optimize |
| 181 | + // this out! |
| 182 | + for (auto i = bench_loop; i; i--) { |
184 | 183 | const auto start{std::chrono::high_resolution_clock::now()};
|
185 | 184 | count++;
|
186 | 185 | const auto end{std::chrono::high_resolution_clock::now()};
|
187 |
| - empty += (double) |
188 |
| - (std::chrono::duration_cast<std::chrono::microseconds>(end - start)).count(); |
| 186 | + empty += |
| 187 | + (double)(std::chrono::duration_cast<std::chrono::microseconds>( |
| 188 | + end - start)) |
| 189 | + .count(); |
189 | 190 | }
|
190 | 191 | assert(count == bench_loop);
|
191 |
| - empty /= (double) bench_loop; |
| 192 | + empty /= (double)bench_loop; |
192 | 193 |
|
193 | 194 | // execution time evaluation
|
194 |
| - for (auto i = bench_loop; i; i--) { |
| 195 | + for (auto i = bench_loop; i; i--) { |
195 | 196 | const auto start{std::chrono::high_resolution_clock::now()};
|
196 | 197 |
|
197 | 198 | // force fast evaluation
|
198 | 199 | subresult = evaluator.validate(schema_template, instance);
|
199 | 200 |
|
200 | 201 | const auto end{std::chrono::high_resolution_clock::now()};
|
201 |
| - const auto delay = (double) (std::chrono::duration_cast< |
202 |
| - std::chrono::microseconds>(end - start)).count() - empty; |
| 202 | + const auto delay = |
| 203 | + (double)(std::chrono::duration_cast<std::chrono::microseconds>( |
| 204 | + end - start)) |
| 205 | + .count() - |
| 206 | + empty; |
203 | 207 |
|
204 | 208 | sum += delay;
|
205 | 209 | sum2 += delay * delay;
|
206 | 210 | }
|
207 | 211 |
|
208 | 212 | // compute and show average execution time and standard deviation
|
209 |
| - auto avg = sum / (double) bench_loop; |
210 |
| - auto stdev = sqrt(sum2 / (double) bench_loop - avg * avg); |
| 213 | + auto avg = sum / (double)bench_loop; |
| 214 | + auto stdev = sqrt(sum2 / (double)bench_loop - avg * avg); |
211 | 215 | std::cout << std::fixed;
|
212 | 216 | std::cout.precision(3);
|
213 |
| - std::cout << "took: " << avg << " +- " << stdev << " us (" << empty << ")\n"; |
| 217 | + std::cout << "took: " << avg << " +- " << stdev << " us (" << empty |
| 218 | + << ")\n"; |
214 | 219 |
|
215 | 220 | if (!subresult) {
|
216 | 221 | error << "error: Schema validation failure\n";
|
|
0 commit comments