Index: media/base/sinc_resampler_perftest.cc |
diff --git a/media/base/sinc_resampler_perftest.cc b/media/base/sinc_resampler_perftest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6f777ee204abb86ba5ca846b4dd6edd01868dbf4 |
--- /dev/null |
+++ b/media/base/sinc_resampler_perftest.cc |
@@ -0,0 +1,81 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/cpu.h" |
+#include "base/time/time.h" |
+#include "media/base/sinc_resampler.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "testing/perf/perf_test.h" |
+ |
+namespace media { |
+ |
+static const int kBenchmarkIterations = 50000000; |
+ |
+static const double kSampleRateRatio = 192000.0 / 44100.0; |
+static const double kKernelInterpolationFactor = 0.5; |
+ |
+// Helper class to ensure ChunkedResample() functions properly. |
+class MockSource { |
+ public: |
+ MOCK_METHOD2(ProvideInput, void(int frames, float* destination)); |
scherkus (not reviewing)
2013/10/29 00:13:45
it doesn't look like this class is doing anything
rileya (GONE FROM CHROMIUM)
2013/10/29 01:23:30
Seems to work, done.
|
+}; |
+ |
+// Define platform independent function name for Convolve* tests. |
+#if defined(ARCH_CPU_X86_FAMILY) |
+#define CONVOLVE_FUNC Convolve_SSE |
+#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) |
+#define CONVOLVE_FUNC Convolve_NEON |
+#endif |
+ |
+void RunConvolveBenchmark( |
scherkus (not reviewing)
2013/10/29 00:13:45
static
|
+ SincResampler& resampler, |
scherkus (not reviewing)
2013/10/29 00:13:45
the only time we pass as reference is when its con
|
+ float (*convolve_fn)(const float*, const float*, const float*, double), |
rileya (GONE FROM CHROMIUM)
2013/10/28 23:38:57
Here and in the vector math tests I pass a functio
scherkus (not reviewing)
2013/10/29 00:13:45
I'd wager the overhead is dwarfed by the convolvin
rileya (GONE FROM CHROMIUM)
2013/10/29 01:23:30
Yeah that was what I thought, I'll try to take a l
|
+ bool aligned, |
+ const std::string& trace_name) { |
+ base::TimeTicks start = base::TimeTicks::HighResNow(); |
+ for (int i = 0; i < kBenchmarkIterations; ++i) { |
+ convolve_fn(resampler.get_kernel_for_testing() + (aligned ? 0 : 1), |
+ resampler.get_kernel_for_testing(), |
+ resampler.get_kernel_for_testing(), |
+ kKernelInterpolationFactor); |
+ } |
+ double total_time_seconds = |
+ (base::TimeTicks::HighResNow() - start).InSecondsF(); |
+ perf_test::PrintResult("sinc_resampler_convolve", |
+ "", |
+ trace_name, |
+ kBenchmarkIterations / total_time_seconds, |
+ "runs/s", |
+ true); |
+} |
+ |
+// Benchmark for the various Convolve() methods. Make sure to build with |
+// branding=Chrome so that DCHECKs are compiled out when benchmarking. |
+TEST(SincResamplerPerfTest, Convolve) { |
+ // Initialize a dummy resampler. |
+ MockSource mock_source; |
+ SincResampler resampler( |
+ kSampleRateRatio, SincResampler::kDefaultRequestSize, |
+ base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); |
+ |
+ RunConvolveBenchmark( |
+ resampler, SincResampler::Convolve_C, true, "unoptimized_aligned"); |
+ |
+#if defined(CONVOLVE_FUNC) |
+#if defined(ARCH_CPU_X86_FAMILY) |
+ ASSERT_TRUE(base::CPU().has_sse()); |
+#endif |
+ RunConvolveBenchmark( |
+ resampler, SincResampler::CONVOLVE_FUNC, true, "optimized_aligned"); |
+ RunConvolveBenchmark( |
+ resampler, SincResampler::CONVOLVE_FUNC, false, "optimized_unaligned"); |
+#endif |
+} |
+ |
+#undef CONVOLVE_FUNC |
+ |
+} // namespace media |