xref: /aosp_15_r20/external/libvpx/test/bench.cc (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
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 
11 #include <stdio.h>
12 #include <algorithm>
13 #include <cstdlib>
14 
15 #include "test/bench.h"
16 #include "vpx_ports/vpx_timer.h"
17 
RunNTimes(int n)18 void AbstractBench::RunNTimes(int n) {
19   for (int r = 0; r < VPX_BENCH_ROBUST_ITER; r++) {
20     vpx_usec_timer timer;
21     vpx_usec_timer_start(&timer);
22     for (int j = 0; j < n; ++j) {
23       Run();
24     }
25     vpx_usec_timer_mark(&timer);
26     times_[r] = static_cast<int>(vpx_usec_timer_elapsed(&timer));
27   }
28 }
29 
PrintMedian(const char * title)30 void AbstractBench::PrintMedian(const char *title) {
31   std::sort(times_, times_ + VPX_BENCH_ROBUST_ITER);
32   const int med = times_[VPX_BENCH_ROBUST_ITER >> 1];
33   int sad = 0;
34   for (int t = 0; t < VPX_BENCH_ROBUST_ITER; t++) {
35     sad += abs(times_[t] - med);
36   }
37   printf("[%10s] %s %.1f ms ( ±%.1f ms )\n", "BENCH ", title, med / 1000.0,
38          sad / (VPX_BENCH_ROBUST_ITER * 1000.0));
39 }
40