• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "base/time/time.h"
8 #include "media/base/sinc_resampler.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/perf/perf_test.h"
12 
13 namespace media {
14 
15 static const int kBenchmarkIterations = 50000000;
16 
17 static const double kSampleRateRatio = 192000.0 / 44100.0;
18 static const double kKernelInterpolationFactor = 0.5;
19 
20 // Helper function to provide no input to SincResampler's Convolve benchmark.
DoNothing(int frames,float * destination)21 static void DoNothing(int frames, float* destination) {}
22 
23 // Define platform independent function name for Convolve* tests.
24 #if defined(ARCH_CPU_X86_FAMILY)
25 #define CONVOLVE_FUNC Convolve_SSE
26 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
27 #define CONVOLVE_FUNC Convolve_NEON
28 #endif
29 
RunConvolveBenchmark(SincResampler * resampler,float (* convolve_fn)(const float *,const float *,const float *,double),bool aligned,const std::string & trace_name)30 static void RunConvolveBenchmark(
31     SincResampler* resampler,
32     float (*convolve_fn)(const float*, const float*, const float*, double),
33     bool aligned,
34     const std::string& trace_name) {
35   base::TimeTicks start = base::TimeTicks::HighResNow();
36   for (int i = 0; i < kBenchmarkIterations; ++i) {
37     convolve_fn(resampler->get_kernel_for_testing() + (aligned ? 0 : 1),
38                 resampler->get_kernel_for_testing(),
39                 resampler->get_kernel_for_testing(),
40                 kKernelInterpolationFactor);
41   }
42   double total_time_milliseconds =
43       (base::TimeTicks::HighResNow() - start).InMillisecondsF();
44   perf_test::PrintResult("sinc_resampler_convolve",
45                          "",
46                          trace_name,
47                          kBenchmarkIterations / total_time_milliseconds,
48                          "runs/ms",
49                          true);
50 }
51 
52 // Benchmark for the various Convolve() methods.  Make sure to build with
53 // branding=Chrome so that DCHECKs are compiled out when benchmarking.
TEST(SincResamplerPerfTest,Convolve)54 TEST(SincResamplerPerfTest, Convolve) {
55   SincResampler resampler(kSampleRateRatio,
56                           SincResampler::kDefaultRequestSize,
57                           base::Bind(&DoNothing));
58 
59   RunConvolveBenchmark(
60       &resampler, SincResampler::Convolve_C, true, "unoptimized_aligned");
61 
62 #if defined(CONVOLVE_FUNC)
63   RunConvolveBenchmark(
64       &resampler, SincResampler::CONVOLVE_FUNC, true, "optimized_aligned");
65   RunConvolveBenchmark(
66       &resampler, SincResampler::CONVOLVE_FUNC, false, "optimized_unaligned");
67 #endif
68 }
69 
70 #undef CONVOLVE_FUNC
71 
72 } // namespace media
73