Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / media / base / sinc_resampler_perftest.cc
blob5ee33481b5586bfc496e7d009c9d710d508e9f7b
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.
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"
13 namespace media {
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
28 #endif
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::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",
45 "",
46 trace_name,
47 kBenchmarkIterations / total_time_milliseconds,
48 "runs/ms",
49 true);
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));
59 RunConvolveBenchmark(
60 &resampler, SincResampler::Convolve_C, true, "unoptimized_aligned");
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
70 #undef CONVOLVE_FUNC
72 } // namespace media