Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: media/base/yuv_convert_perftest.cc

Issue 238353008: Add perf tests for simd yuv->rgb conversion functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@m
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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/base_paths.h"
6 #include "base/cpu.h"
7 #include "base/file_util.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "base/time/time.h"
11 #include "media/base/djb2.h"
scherkus (not reviewing) 2014/04/22 18:10:56 this isn't used anywhere -- remove (might be wort
rileya (GONE FROM CHROMIUM) 2014/04/23 18:09:21 Whoops, yeah I grabbed this from yuv_convert_unitt
12 #include "media/base/simd/convert_rgb_to_yuv.h"
13 #include "media/base/simd/convert_yuv_to_rgb.h"
14 #include "media/base/simd/filter_yuv.h"
15 #include "media/base/yuv_convert.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/perf/perf_test.h"
18 #include "ui/gfx/rect.h"
19
scherkus (not reviewing) 2014/04/22 18:10:56 namespace media should go here
rileya (GONE FROM CHROMIUM) 2014/04/23 18:09:21 Done.
20 // Size of raw image.
21 static const int kSourceWidth = 640;
22 static const int kSourceHeight = 360;
23 static const int kSourceYSize = kSourceWidth * kSourceHeight;
24 static const int kSourceUOffset = kSourceYSize;
25 static const int kSourceVOffset = kSourceYSize * 5 / 4;
26 static const int kBpp = 4;
27
28 // Width of the row to convert. Odd so that we exercise the ending
29 // one-pixel-leftover case.
30 static const int kWidth = 639;
31
32 // Surface sizes for various test files.
33 static const int kYUV12Size = kSourceYSize * 12 / 8;
34 static const int kRGBSize = kSourceYSize * kBpp;
35
36 static const int kPerfTestIterations = 2000;
37
38 // Helper for reading test data into a scoped_ptr<uint8[]>.
39 static void ReadData(const base::FilePath::CharType* filename,
40 int expected_size,
41 scoped_ptr<uint8[]>* data) {
42 data->reset(new uint8[expected_size]);
43
44 base::FilePath path;
45 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path));
46 path = path.Append(FILE_PATH_LITERAL("media"))
47 .Append(FILE_PATH_LITERAL("test"))
48 .Append(FILE_PATH_LITERAL("data"))
49 .Append(filename);
50
51 // Verify file size is correct.
52 int64 actual_size = 0;
53 base::GetFileSize(path, &actual_size);
54 CHECK_EQ(actual_size, expected_size);
55
56 // Verify bytes read are correct.
57 int bytes_read = base::ReadFile(
58 path, reinterpret_cast<char*>(data->get()), expected_size);
59 CHECK_EQ(bytes_read, expected_size);
60 }
61
62 class YUVConvertPerfTest : public testing::Test {
63 public:
64 YUVConvertPerfTest()
65 : yuv_bytes_(new uint8[kYUV12Size]),
66 rgb_bytes_converted_(new uint8[kRGBSize]) {}
67
68 void InitYV12Data() {
69 ReadData(
scherkus (not reviewing) 2014/04/22 18:10:56 nit: is it worth having ReadData() if there's only
rileya (GONE FROM CHROMIUM) 2014/04/23 18:09:21 Removed.
70 FILE_PATH_LITERAL("bali_640x360_P420.yuv"), kYUV12Size, &yuv_bytes_);
71 }
72
73 scoped_ptr<uint8[]> yuv_bytes_;
74 scoped_ptr<uint8[]> rgb_bytes_converted_;
75 };
scherkus (not reviewing) 2014/04/22 18:10:56 DISALLOW etc..
rileya (GONE FROM CHROMIUM) 2014/04/23 18:09:21 Added DISALLOW_COPY_AND_ASSIGN.
76
77 namespace media {
78
79 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY)
80 TEST_F(YUVConvertPerfTest, ConvertYUVToRGB32Row_MMX) {
81 base::CPU cpu;
82 if (!cpu.has_mmx()) {
scherkus (not reviewing) 2014/04/22 18:10:56 considering our minimum supported arch is SSE2 I'd
rileya (GONE FROM CHROMIUM) 2014/04/23 18:09:21 Probably not many, but I was following the convent
83 LOG(WARNING) << "System not supported. Test skipped.";
84 return;
85 }
86
87 InitYV12Data();
88
89 base::TimeTicks start = base::TimeTicks::HighResNow();
90 for (int i = 0; i < kPerfTestIterations; ++i) {
91 for (int row = 0; row < kSourceHeight; ++row) {
92 int chroma_row = row / 2;
93 ConvertYUVToRGB32Row_MMX(
94 yuv_bytes_.get() + row * kSourceWidth,
95 yuv_bytes_.get() + kSourceUOffset + (chroma_row * kSourceWidth / 2),
96 yuv_bytes_.get() + kSourceVOffset + (chroma_row * kSourceWidth / 2),
97 rgb_bytes_converted_.get(),
98 kWidth);
99 }
100 }
101 double total_time_seconds =
102 (base::TimeTicks::HighResNow() - start).InSecondsF();
103 perf_test::PrintResult(
104 "yuv_convert_perftest", "", "ConvertYUVToRGB32Row_MMX",
105 kPerfTestIterations / total_time_seconds, "runs/s", true);
106
107 media::EmptyRegisterState();
108 }
109
110 TEST_F(YUVConvertPerfTest, ConvertYUVToRGB32Row_SSE) {
111 base::CPU cpu;
112 if (!cpu.has_sse()) {
113 LOG(WARNING) << "System not supported. Test skipped.";
114 return;
115 }
116
117 InitYV12Data();
scherkus (not reviewing) 2014/04/22 18:10:56 this is called every time -- move into ctor?
rileya (GONE FROM CHROMIUM) 2014/04/23 18:09:21 Done.
118
119 base::TimeTicks start = base::TimeTicks::HighResNow();
120 for (int i = 0; i < kPerfTestIterations; ++i) {
121 for (int row = 0; row < kSourceHeight; ++row) {
122 int chroma_row = row / 2;
123 ConvertYUVToRGB32Row_SSE(
124 yuv_bytes_.get() + row * kSourceWidth,
125 yuv_bytes_.get() + kSourceUOffset + (chroma_row * kSourceWidth / 2),
126 yuv_bytes_.get() + kSourceVOffset + (chroma_row * kSourceWidth / 2),
127 rgb_bytes_converted_.get(),
128 kWidth);
129 }
130 }
131 double total_time_seconds =
132 (base::TimeTicks::HighResNow() - start).InSecondsF();
133 perf_test::PrintResult(
134 "yuv_convert_perftest", "", "ConvertYUVToRGB32Row_SSE",
135 kPerfTestIterations / total_time_seconds, "runs/s", true);
136 media::EmptyRegisterState();
137 }
138
139 TEST_F(YUVConvertPerfTest, ScaleYUVToRGB32Row_MMX) {
140 base::CPU cpu;
141 if (!cpu.has_mmx()) {
142 LOG(WARNING) << "System not supported. Test skipped.";
143 return;
144 }
145
146 InitYV12Data();
147
148 const int kSourceDx = 80000; // This value means a scale down.
149
150 base::TimeTicks start = base::TimeTicks::HighResNow();
151 for (int i = 0; i < kPerfTestIterations; ++i) {
152 for (int row = 0; row < kSourceHeight; ++row) {
153 int chroma_row = row / 2;
154 ScaleYUVToRGB32Row_MMX(
155 yuv_bytes_.get() + row * kSourceWidth,
156 yuv_bytes_.get() + kSourceUOffset + (chroma_row * kSourceWidth / 2),
157 yuv_bytes_.get() + kSourceVOffset + (chroma_row * kSourceWidth / 2),
158 rgb_bytes_converted_.get(),
159 kWidth,
160 kSourceDx);
161 }
162 }
163 double total_time_seconds =
164 (base::TimeTicks::HighResNow() - start).InSecondsF();
165 perf_test::PrintResult(
166 "yuv_convert_perftest", "", "ScaleYUVToRGB32Row_MMX",
167 kPerfTestIterations / total_time_seconds, "runs/s", true);
168 media::EmptyRegisterState();
169 }
170
171 TEST_F(YUVConvertPerfTest, ScaleYUVToRGB32Row_SSE) {
172 base::CPU cpu;
173 if (!cpu.has_sse()) {
174 LOG(WARNING) << "System not supported. Test skipped.";
175 return;
176 }
177
178 InitYV12Data();
179
180 const int kSourceDx = 80000; // This value means a scale down.
181
182 base::TimeTicks start = base::TimeTicks::HighResNow();
183 for (int i = 0; i < kPerfTestIterations; ++i) {
184 for (int row = 0; row < kSourceHeight; ++row) {
185 int chroma_row = row / 2;
186 ScaleYUVToRGB32Row_SSE(
187 yuv_bytes_.get() + row * kSourceWidth,
188 yuv_bytes_.get() + kSourceUOffset + (chroma_row * kSourceWidth / 2),
189 yuv_bytes_.get() + kSourceVOffset + (chroma_row * kSourceWidth / 2),
190 rgb_bytes_converted_.get(),
191 kWidth,
192 kSourceDx);
193 }
194 }
195 double total_time_seconds =
196 (base::TimeTicks::HighResNow() - start).InSecondsF();
197 perf_test::PrintResult(
198 "yuv_convert_perftest", "", "ScaleYUVToRGB32Row_SSE",
199 kPerfTestIterations / total_time_seconds, "runs/s", true);
200 media::EmptyRegisterState();
201 }
202
203 TEST_F(YUVConvertPerfTest, LinearScaleYUVToRGB32Row_MMX) {
204 base::CPU cpu;
205 if (!cpu.has_mmx()) {
206 LOG(WARNING) << "System not supported. Test skipped.";
207 return;
208 }
209
210 InitYV12Data();
211
212 const int kSourceDx = 80000; // This value means a scale down.
213
214 base::TimeTicks start = base::TimeTicks::HighResNow();
215 for (int i = 0; i < kPerfTestIterations; ++i) {
216 for (int row = 0; row < kSourceHeight; ++row) {
217 int chroma_row = row / 2;
218 LinearScaleYUVToRGB32Row_MMX(
219 yuv_bytes_.get() + row * kSourceWidth,
220 yuv_bytes_.get() + kSourceUOffset + (chroma_row * kSourceWidth / 2),
221 yuv_bytes_.get() + kSourceVOffset + (chroma_row * kSourceWidth / 2),
222 rgb_bytes_converted_.get(),
223 kWidth,
224 kSourceDx);
225 }
226 }
227 double total_time_seconds =
228 (base::TimeTicks::HighResNow() - start).InSecondsF();
229 perf_test::PrintResult(
230 "yuv_convert_perftest", "", "LinearScaleYUVToRGB32Row_MMX",
231 kPerfTestIterations / total_time_seconds, "runs/s", true);
232 media::EmptyRegisterState();
233 }
234
235 TEST_F(YUVConvertPerfTest, LinearScaleYUVToRGB32Row_SSE) {
236 base::CPU cpu;
237 if (!cpu.has_sse()) {
238 LOG(WARNING) << "System not supported. Test skipped.";
239 return;
240 }
241
242 InitYV12Data();
243
244 const int kSourceDx = 80000; // This value means a scale down.
245
246 base::TimeTicks start = base::TimeTicks::HighResNow();
247 for (int i = 0; i < kPerfTestIterations; ++i) {
248 for (int row = 0; row < kSourceHeight; ++row) {
249 int chroma_row = row / 2;
250 LinearScaleYUVToRGB32Row_SSE(
251 yuv_bytes_.get() + row * kSourceWidth,
252 yuv_bytes_.get() + kSourceUOffset + (chroma_row * kSourceWidth / 2),
253 yuv_bytes_.get() + kSourceVOffset + (chroma_row * kSourceWidth / 2),
254 rgb_bytes_converted_.get(),
255 kWidth,
256 kSourceDx);
257 }
258 }
259 double total_time_seconds =
260 (base::TimeTicks::HighResNow() - start).InSecondsF();
261 perf_test::PrintResult(
262 "yuv_convert_perftest", "", "LinearScaleYUVToRGB32Row_SSE",
263 kPerfTestIterations / total_time_seconds, "runs/s", true);
264 media::EmptyRegisterState();
265 }
266
267 #endif // !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY)
268
269 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698