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"
8 #include "base/time/time.h"
9 #include "media/base/sinc_resampler.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/perf/perf_test.h"
16 static const int kBenchmarkIterations
= 50000000;
18 static const double kSampleRateRatio
= 192000.0 / 44100.0;
19 static const double kKernelInterpolationFactor
= 0.5;
21 // Helper function to provide no input to SincResampler's Convolve benchmark.
22 static void DoNothing(int frames
, float* destination
) {}
24 // Define platform independent function name for Convolve* tests.
25 #if defined(ARCH_CPU_X86_FAMILY)
26 #define CONVOLVE_FUNC Convolve_SSE
27 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
28 #define CONVOLVE_FUNC Convolve_NEON
31 static void RunConvolveBenchmark(
32 SincResampler
* resampler
,
33 float (*convolve_fn
)(const float*, const float*, const float*, double),
35 const std::string
& trace_name
) {
36 base::TimeTicks start
= base::TimeTicks::HighResNow();
37 for (int i
= 0; i
< kBenchmarkIterations
; ++i
) {
38 convolve_fn(resampler
->get_kernel_for_testing() + (aligned
? 0 : 1),
39 resampler
->get_kernel_for_testing(),
40 resampler
->get_kernel_for_testing(),
41 kKernelInterpolationFactor
);
43 double total_time_milliseconds
=
44 (base::TimeTicks::HighResNow() - start
).InMillisecondsF();
45 perf_test::PrintResult("sinc_resampler_convolve",
48 kBenchmarkIterations
/ total_time_milliseconds
,
53 // Benchmark for the various Convolve() methods. Make sure to build with
54 // branding=Chrome so that DCHECKs are compiled out when benchmarking.
55 TEST(SincResamplerPerfTest
, Convolve
) {
56 SincResampler
resampler(kSampleRateRatio
,
57 SincResampler::kDefaultRequestSize
,
58 base::Bind(&DoNothing
));
61 &resampler
, SincResampler::Convolve_C
, true, "unoptimized_aligned");
63 #if defined(CONVOLVE_FUNC)
64 #if defined(ARCH_CPU_X86_FAMILY)
65 ASSERT_TRUE(base::CPU().has_sse());
68 &resampler
, SincResampler::CONVOLVE_FUNC
, true, "optimized_aligned");
70 &resampler
, SincResampler::CONVOLVE_FUNC
, false, "optimized_unaligned");