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/cpu.h" | |
| 6 #include "base/memory/aligned_memory.h" | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/time/time.h" | |
| 9 #include "media/base/vector_math.h" | |
| 10 #include "media/base/vector_math_testing.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "testing/perf/perf_test.h" | |
| 13 | |
| 14 // Default test values. | |
| 15 static const float kScale = 0.5; | |
| 16 static const float kInputFillValue = 1.0; | |
| 17 static const float kOutputFillValue = 3.0; | |
| 18 | |
| 19 using base::TimeTicks; | |
| 20 using std::fill; | |
| 21 | |
| 22 namespace media { | |
| 23 | |
| 24 static const int kBenchmarkIterations = 200000; | |
| 25 | |
| 26 class VectorMathPerfTest : public testing::Test { | |
| 27 public: | |
| 28 static const int kVectorSize = 8192; | |
| 29 | |
| 30 VectorMathPerfTest() { | |
| 31 // Initialize input and output vectors. | |
| 32 input_vector.reset(static_cast<float*>(base::AlignedAlloc( | |
| 33 sizeof(float) * kVectorSize, vector_math::kRequiredAlignment))); | |
| 34 output_vector.reset(static_cast<float*>(base::AlignedAlloc( | |
| 35 sizeof(float) * kVectorSize, vector_math::kRequiredAlignment))); | |
| 36 } | |
| 37 | |
| 38 void FillTestVectors(float input, float output) { | |
| 39 // Setup input and output vectors. | |
| 40 fill(input_vector.get(), input_vector.get() + kVectorSize, input); | |
| 41 fill(output_vector.get(), output_vector.get() + kVectorSize, output); | |
| 42 } | |
| 43 | |
| 44 void RunBenchmark(void (*fn)(const float[], float, int, float[]), | |
| 45 bool aligned, | |
| 46 const std::string& test_name, | |
| 47 const std::string& trace_name) { | |
| 48 FillTestVectors(kInputFillValue, kOutputFillValue); | |
| 49 TimeTicks start = TimeTicks::HighResNow(); | |
| 50 for (int i = 0; i < kBenchmarkIterations; ++i) { | |
| 51 fn(input_vector.get(), | |
| 52 kScale, | |
| 53 kVectorSize - (aligned ? 0 : 1), | |
| 54 output_vector.get()); | |
| 55 } | |
| 56 double total_time_seconds = (TimeTicks::HighResNow() - start).InSecondsF(); | |
| 57 perf_test::PrintResult(test_name, | |
| 58 "", | |
| 59 trace_name, | |
| 60 kBenchmarkIterations / total_time_seconds, | |
| 61 "runs/s", | |
| 62 true); | |
| 63 } | |
| 64 | |
| 65 protected: | |
| 66 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> input_vector; | |
| 67 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> output_vector; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(VectorMathPerfTest); | |
| 70 }; | |
| 71 | |
| 72 // Define platform independent function name for FMAC* perf tests. | |
| 73 #if defined(ARCH_CPU_X86_FAMILY) | |
| 74 #define FMAC_FUNC FMAC_SSE | |
| 75 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) | |
| 76 #define FMAC_FUNC FMAC_NEON | |
| 77 #endif | |
| 78 | |
| 79 // Benchmark for each optimized vector_math::FMAC() method. | |
| 80 TEST_F(VectorMathPerfTest, FMAC) { | |
| 81 // Benchmark FMAC_C(). | |
| 82 RunBenchmark( | |
| 83 vector_math::FMAC_C, true, "vector_math_fmac", "unoptimized"); | |
| 84 #if defined(FMAC_FUNC) | |
| 85 #if defined(ARCH_CPU_X86_FAMILY) | |
| 86 ASSERT_TRUE(base::CPU().has_sse()); | |
| 87 #endif | |
| 88 // Benchmark FMAC_FUNC() with unaligned size. | |
| 89 ASSERT_NE((kVectorSize - 1) % (vector_math::kRequiredAlignment / | |
| 90 sizeof(float)), 0U); | |
|
scherkus (not reviewing)
2013/10/29 00:13:45
indent here should be aligned at (
| |
| 91 RunBenchmark( | |
| 92 vector_math::FMAC_FUNC, false, "vector_math_fmac", "optimized_unaligned"); | |
| 93 // Benchmark FMAC_FUNC() with aligned size. | |
| 94 ASSERT_EQ(kVectorSize % (vector_math::kRequiredAlignment / sizeof(float)), | |
| 95 0U); | |
| 96 RunBenchmark( | |
| 97 vector_math::FMAC_FUNC, true, "vector_math_fmac", "optimized_aligned"); | |
| 98 #endif | |
| 99 } | |
| 100 | |
| 101 #undef FMAC_FUNC | |
| 102 | |
| 103 // Define platform independent function name for FMULBenchmark* tests. | |
| 104 #if defined(ARCH_CPU_X86_FAMILY) | |
| 105 #define FMUL_FUNC FMUL_SSE | |
| 106 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) | |
| 107 #define FMUL_FUNC FMUL_NEON | |
| 108 #endif | |
| 109 | |
| 110 // Benchmark for each optimized vector_math::FMUL() method. | |
| 111 TEST_F(VectorMathPerfTest, FMUL) { | |
| 112 // Benchmark FMUL_C(). | |
| 113 RunBenchmark( | |
| 114 vector_math::FMUL_C, true, "vector_math_fmul", "unoptimized"); | |
| 115 #if defined(FMUL_FUNC) | |
| 116 #if defined(ARCH_CPU_X86_FAMILY) | |
| 117 ASSERT_TRUE(base::CPU().has_sse()); | |
| 118 #endif | |
| 119 // Benchmark FMUL_FUNC() with unaligned size. | |
| 120 ASSERT_NE((kVectorSize - 1) % (vector_math::kRequiredAlignment / | |
| 121 sizeof(float)), 0U); | |
|
scherkus (not reviewing)
2013/10/29 00:13:45
ditto
| |
| 122 RunBenchmark( | |
| 123 vector_math::FMUL_FUNC, false, "vector_math_fmac", "optimized_unaligned"); | |
| 124 // Benchmark FMUL_FUNC() with aligned size. | |
| 125 ASSERT_EQ(kVectorSize % (vector_math::kRequiredAlignment / sizeof(float)), | |
| 126 0U); | |
| 127 RunBenchmark( | |
| 128 vector_math::FMUL_FUNC, true, "vector_math_fmac", "optimized_aligned"); | |
| 129 #endif | |
| 130 } | |
| 131 | |
| 132 #undef FMUL_FUNC | |
| 133 | |
| 134 } // namespace media | |
| OLD | NEW |