Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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/cpu.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" | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 static const int kBenchmarkIterations = 50000000; | |
| 17 | |
| 18 static const double kSampleRateRatio = 192000.0 / 44100.0; | |
| 19 static const double kKernelInterpolationFactor = 0.5; | |
| 20 | |
| 21 // Helper class to ensure ChunkedResample() functions properly. | |
| 22 class MockSource { | |
| 23 public: | |
| 24 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.
| |
| 25 }; | |
| 26 | |
| 27 // Define platform independent function name for Convolve* tests. | |
| 28 #if defined(ARCH_CPU_X86_FAMILY) | |
| 29 #define CONVOLVE_FUNC Convolve_SSE | |
| 30 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) | |
| 31 #define CONVOLVE_FUNC Convolve_NEON | |
| 32 #endif | |
| 33 | |
| 34 void RunConvolveBenchmark( | |
|
scherkus (not reviewing)
2013/10/29 00:13:45
static
| |
| 35 SincResampler& resampler, | |
|
scherkus (not reviewing)
2013/10/29 00:13:45
the only time we pass as reference is when its con
| |
| 36 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
| |
| 37 bool aligned, | |
| 38 const std::string& trace_name) { | |
| 39 base::TimeTicks start = base::TimeTicks::HighResNow(); | |
| 40 for (int i = 0; i < kBenchmarkIterations; ++i) { | |
| 41 convolve_fn(resampler.get_kernel_for_testing() + (aligned ? 0 : 1), | |
| 42 resampler.get_kernel_for_testing(), | |
| 43 resampler.get_kernel_for_testing(), | |
| 44 kKernelInterpolationFactor); | |
| 45 } | |
| 46 double total_time_seconds = | |
| 47 (base::TimeTicks::HighResNow() - start).InSecondsF(); | |
| 48 perf_test::PrintResult("sinc_resampler_convolve", | |
| 49 "", | |
| 50 trace_name, | |
| 51 kBenchmarkIterations / total_time_seconds, | |
| 52 "runs/s", | |
| 53 true); | |
| 54 } | |
| 55 | |
| 56 // Benchmark for the various Convolve() methods. Make sure to build with | |
| 57 // branding=Chrome so that DCHECKs are compiled out when benchmarking. | |
| 58 TEST(SincResamplerPerfTest, Convolve) { | |
| 59 // Initialize a dummy resampler. | |
| 60 MockSource mock_source; | |
| 61 SincResampler resampler( | |
| 62 kSampleRateRatio, SincResampler::kDefaultRequestSize, | |
| 63 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); | |
| 64 | |
| 65 RunConvolveBenchmark( | |
| 66 resampler, SincResampler::Convolve_C, true, "unoptimized_aligned"); | |
| 67 | |
| 68 #if defined(CONVOLVE_FUNC) | |
| 69 #if defined(ARCH_CPU_X86_FAMILY) | |
| 70 ASSERT_TRUE(base::CPU().has_sse()); | |
| 71 #endif | |
| 72 RunConvolveBenchmark( | |
| 73 resampler, SincResampler::CONVOLVE_FUNC, true, "optimized_aligned"); | |
| 74 RunConvolveBenchmark( | |
| 75 resampler, SincResampler::CONVOLVE_FUNC, false, "optimized_unaligned"); | |
| 76 #endif | |
| 77 } | |
| 78 | |
| 79 #undef CONVOLVE_FUNC | |
| 80 | |
| 81 } // namespace media | |
| OLD | NEW |