bench.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2018 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <stdio.h>
  11. #include <algorithm>
  12. #include "test/bench.h"
  13. #include "vpx_ports/vpx_timer.h"
  14. void AbstractBench::RunNTimes(int n) {
  15. for (int r = 0; r < VPX_BENCH_ROBUST_ITER; r++) {
  16. vpx_usec_timer timer;
  17. vpx_usec_timer_start(&timer);
  18. for (int j = 0; j < n; ++j) {
  19. Run();
  20. }
  21. vpx_usec_timer_mark(&timer);
  22. times_[r] = static_cast<int>(vpx_usec_timer_elapsed(&timer));
  23. }
  24. }
  25. void AbstractBench::PrintMedian(const char *title) {
  26. std::sort(times_, times_ + VPX_BENCH_ROBUST_ITER);
  27. const int med = times_[VPX_BENCH_ROBUST_ITER >> 1];
  28. int sad = 0;
  29. for (int t = 0; t < VPX_BENCH_ROBUST_ITER; t++) {
  30. sad += abs(times_[t] - med);
  31. }
  32. printf("[%10s] %s %.1f ms ( ±%.1f ms )\n", "BENCH ", title, med / 1000.0,
  33. sad / (VPX_BENCH_ROBUST_ITER * 1000.0));
  34. }