Skip to content

Commit 92f47be

Browse files
author
Fabien Coelho
committed
use nanos instead of micros to improve precision
1 parent fdf6d1d commit 92f47be

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/command_validate.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,17 @@ auto sourcemeta::jsonschema::cli::validate(
175175
bool subresult{true};
176176
if (benchmark) {
177177
double sum = 0.0, sum2 = 0.0, empty = 0.0;
178-
size_t count = 0;
179178

180179
// overhead evaluation, if the compiler is kind enough not to optimize
181180
// this out!
182181
for (auto i = bench_loop; i; i--) {
183182
const auto start{std::chrono::high_resolution_clock::now()};
184-
count++;
185183
const auto end{std::chrono::high_resolution_clock::now()};
186184
empty +=
187-
(double)(std::chrono::duration_cast<std::chrono::microseconds>(
185+
(double)(std::chrono::duration_cast<std::chrono::nanoseconds>(
188186
end - start))
189-
.count();
187+
.count() / 1000.0;
190188
}
191-
assert(count == bench_loop);
192189
empty /= (double)bench_loop;
193190

194191
// execution time evaluation
@@ -200,9 +197,9 @@ auto sourcemeta::jsonschema::cli::validate(
200197

201198
const auto end{std::chrono::high_resolution_clock::now()};
202199
const auto delay =
203-
(double)(std::chrono::duration_cast<std::chrono::microseconds>(
200+
(double)(std::chrono::duration_cast<std::chrono::nanoseconds>(
204201
end - start))
205-
.count() -
202+
.count() / 1000.0 -
206203
empty;
207204

208205
sum += delay;

0 commit comments

Comments
 (0)