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