|
6 | 6 | #include "common_types.h" |
7 | 7 | #include "denormal_disabler.h" |
8 | 8 | #include "onnx_converter.h" |
| 9 | +#include <chrono> |
9 | 10 | #include <fstream> |
10 | 11 | #include <random> |
11 | | -#include <sys/time.h> |
12 | 12 | #include <unordered_set> |
13 | 13 |
|
14 | 14 | namespace py = pybind11; |
@@ -469,29 +469,28 @@ double benchmark( |
469 | 469 | pipeline.rep->realize(real, tgt); |
470 | 470 |
|
471 | 471 | // Now benchmark by computing the value of the outputs num_iter times |
472 | | - struct timespec start; |
473 | | - struct timespec end; |
474 | | - clock_gettime(CLOCK_REALTIME, &start); |
| 472 | + using clock = std::chrono::high_resolution_clock; |
| 473 | + auto start = clock::now(); |
475 | 474 | for (int i = 0; i < num_iters; ++i) { |
476 | 475 | // Increment the coefficients store in the cache evictor: this ensures that |
477 | 476 | // all the data left in caches from the previous iteration is flushed out. |
478 | 477 | cache_evictor.flush_caches(); |
479 | 478 | pipeline.rep->realize(real, tgt); |
480 | 479 | } |
481 | | - clock_gettime(CLOCK_REALTIME, &end); |
| 480 | + auto end = clock::now(); |
482 | 481 |
|
483 | 482 | double total_runtime = |
484 | | - (end.tv_sec - start.tv_sec) * 1e9 + end.tv_nsec - start.tv_nsec; |
| 483 | + std::chrono::duration<double, std::nano>(end - start).count(); |
485 | 484 |
|
486 | 485 | // Figure out how long it took to generate new inputs at every iteration |
487 | 486 | // and adjust the runtime accordingly. |
488 | | - clock_gettime(CLOCK_REALTIME, &start); |
| 487 | + start = clock::now(); |
489 | 488 | for (int i = 0; i < num_iters; ++i) { |
490 | 489 | cache_evictor.flush_caches(); |
491 | 490 | } |
492 | | - clock_gettime(CLOCK_REALTIME, &end); |
| 491 | + end = clock::now(); |
493 | 492 | double input_gen_time = |
494 | | - (end.tv_sec - start.tv_sec) * 1e9 + end.tv_nsec - start.tv_nsec; |
| 493 | + std::chrono::duration<double, std::nano>(end - start).count(); |
495 | 494 |
|
496 | 495 | total_runtime -= input_gen_time; |
497 | 496 |
|
|
0 commit comments