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.
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"
15 static const int kBenchmarkIterations
= 50000000;
17 static const double kSampleRateRatio
= 192000.0 / 44100.0;
18 static const double kKernelInterpolationFactor
= 0.5;
20 // Helper function to provide no input to SincResampler's Convolve benchmark.
21 static void DoNothing(int frames
, float* destination
) {}
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
30 static void RunConvolveBenchmark(
31 SincResampler
* resampler
,
32 float (*convolve_fn
)(const float*, const float*, const float*, double),
34 const std::string
& trace_name
) {
35 base::TimeTicks start
= base::TimeTicks::Now();
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
);
42 double total_time_milliseconds
=
43 (base::TimeTicks::Now() - start
).InMillisecondsF();
44 perf_test::PrintResult("sinc_resampler_convolve",
47 kBenchmarkIterations
/ total_time_milliseconds
,
52 // Benchmark for the various Convolve() methods. Make sure to build with
53 // branding=Chrome so that DCHECKs are compiled out when benchmarking.
54 TEST(SincResamplerPerfTest
, Convolve
) {
55 SincResampler
resampler(kSampleRateRatio
,
56 SincResampler::kDefaultRequestSize
,
57 base::Bind(&DoNothing
));
60 &resampler
, SincResampler::Convolve_C
, true, "unoptimized_aligned");
62 #if defined(CONVOLVE_FUNC)
64 &resampler
, SincResampler::CONVOLVE_FUNC
, true, "optimized_aligned");
66 &resampler
, SincResampler::CONVOLVE_FUNC
, false, "optimized_unaligned");