1 /* 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "../unit_test/unit_test.h" 12 13 #include <stdlib.h> // For getenv() 14 15 #include <cstring> 16 17 #include "gflags/gflags.h" 18 19 // Change this to 1000 for benchmarking. 20 // TODO(fbarchard): Add command line parsing to pass this as option. 21 #define BENCHMARK_ITERATIONS 1 22 23 unsigned int fastrand_seed = 0xfb; 24 25 DEFINE_int32(libyuv_width, 0, "width of test image."); 26 DEFINE_int32(libyuv_height, 0, "height of test image."); 27 DEFINE_int32(libyuv_repeat, 0, "number of times to repeat test."); 28 DEFINE_int32(libyuv_flags, 0, 29 "cpu flags for reference code. 1 = C, -1 = SIMD"); 30 DEFINE_int32(libyuv_cpu_info, 0, 31 "cpu flags for benchmark code. 1 = C, -1 = SIMD"); 32 33 // For quicker unittests, default is 128 x 72. But when benchmarking, 34 // default to 720p. Allow size to specify. 35 // Set flags to -1 for benchmarking to avoid slower C code. 36 37 LibYUVConvertTest::LibYUVConvertTest() : 38 benchmark_iterations_(BENCHMARK_ITERATIONS), benchmark_width_(128), 39 benchmark_height_(72), disable_cpu_flags_(1), benchmark_cpu_info_(-1) { 40 const char* repeat = getenv("LIBYUV_REPEAT"); 41 if (repeat) { 42 benchmark_iterations_ = atoi(repeat); // NOLINT 43 } 44 if (FLAGS_libyuv_repeat) { 45 benchmark_iterations_ = FLAGS_libyuv_repeat; 46 } 47 if (benchmark_iterations_ > 1) { 48 benchmark_width_ = 1280; 49 benchmark_height_ = 720; 50 } 51 const char* width = getenv("LIBYUV_WIDTH"); 52 if (width) { 53 benchmark_width_ = atoi(width); // NOLINT 54 } 55 if (FLAGS_libyuv_width) { 56 benchmark_width_ = FLAGS_libyuv_width; 57 } 58 const char* height = getenv("LIBYUV_HEIGHT"); 59 if (height) { 60 benchmark_height_ = atoi(height); // NOLINT 61 } 62 if (FLAGS_libyuv_height) { 63 benchmark_height_ = FLAGS_libyuv_height; 64 } 65 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 66 if (cpu_flags) { 67 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 68 } 69 if (FLAGS_libyuv_flags) { 70 disable_cpu_flags_ = FLAGS_libyuv_flags; 71 } 72 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 73 if (cpu_info) { 74 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 75 } 76 if (FLAGS_libyuv_cpu_info) { 77 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 78 } 79 benchmark_pixels_div256_ = static_cast<int>(( 80 static_cast<double>(Abs(benchmark_width_)) * 81 static_cast<double>(Abs(benchmark_height_)) * 82 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 83 benchmark_pixels_div1280_ = static_cast<int>(( 84 static_cast<double>(Abs(benchmark_width_)) * 85 static_cast<double>(Abs(benchmark_height_)) * 86 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 87 } 88 89 LibYUVColorTest::LibYUVColorTest() : 90 benchmark_iterations_(BENCHMARK_ITERATIONS), benchmark_width_(128), 91 benchmark_height_(72), disable_cpu_flags_(1), benchmark_cpu_info_(-1) { 92 const char* repeat = getenv("LIBYUV_REPEAT"); 93 if (repeat) { 94 benchmark_iterations_ = atoi(repeat); // NOLINT 95 } 96 if (FLAGS_libyuv_repeat) { 97 benchmark_iterations_ = FLAGS_libyuv_repeat; 98 } 99 if (benchmark_iterations_ > 1) { 100 benchmark_width_ = 1280; 101 benchmark_height_ = 720; 102 } 103 const char* width = getenv("LIBYUV_WIDTH"); 104 if (width) { 105 benchmark_width_ = atoi(width); // NOLINT 106 } 107 if (FLAGS_libyuv_width) { 108 benchmark_width_ = FLAGS_libyuv_width; 109 } 110 const char* height = getenv("LIBYUV_HEIGHT"); 111 if (height) { 112 benchmark_height_ = atoi(height); // NOLINT 113 } 114 if (FLAGS_libyuv_height) { 115 benchmark_height_ = FLAGS_libyuv_height; 116 } 117 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 118 if (cpu_flags) { 119 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 120 } 121 if (FLAGS_libyuv_flags) { 122 disable_cpu_flags_ = FLAGS_libyuv_flags; 123 } 124 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 125 if (cpu_info) { 126 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 127 } 128 if (FLAGS_libyuv_cpu_info) { 129 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 130 } 131 benchmark_pixels_div256_ = static_cast<int>(( 132 static_cast<double>(Abs(benchmark_width_)) * 133 static_cast<double>(Abs(benchmark_height_)) * 134 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 135 benchmark_pixels_div1280_ = static_cast<int>(( 136 static_cast<double>(Abs(benchmark_width_)) * 137 static_cast<double>(Abs(benchmark_height_)) * 138 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 139 } 140 141 LibYUVScaleTest::LibYUVScaleTest() : 142 benchmark_iterations_(BENCHMARK_ITERATIONS), benchmark_width_(128), 143 benchmark_height_(72), disable_cpu_flags_(1), benchmark_cpu_info_(-1) { 144 const char* repeat = getenv("LIBYUV_REPEAT"); 145 if (repeat) { 146 benchmark_iterations_ = atoi(repeat); // NOLINT 147 } 148 if (FLAGS_libyuv_repeat) { 149 benchmark_iterations_ = FLAGS_libyuv_repeat; 150 } 151 if (benchmark_iterations_ > 1) { 152 benchmark_width_ = 1280; 153 benchmark_height_ = 720; 154 } 155 const char* width = getenv("LIBYUV_WIDTH"); 156 if (width) { 157 benchmark_width_ = atoi(width); // NOLINT 158 } 159 if (FLAGS_libyuv_width) { 160 benchmark_width_ = FLAGS_libyuv_width; 161 } 162 const char* height = getenv("LIBYUV_HEIGHT"); 163 if (height) { 164 benchmark_height_ = atoi(height); // NOLINT 165 } 166 if (FLAGS_libyuv_height) { 167 benchmark_height_ = FLAGS_libyuv_height; 168 } 169 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 170 if (cpu_flags) { 171 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 172 } 173 if (FLAGS_libyuv_flags) { 174 disable_cpu_flags_ = FLAGS_libyuv_flags; 175 } 176 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 177 if (cpu_info) { 178 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 179 } 180 if (FLAGS_libyuv_cpu_info) { 181 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 182 } 183 benchmark_pixels_div256_ = static_cast<int>(( 184 static_cast<double>(Abs(benchmark_width_)) * 185 static_cast<double>(Abs(benchmark_height_)) * 186 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 187 benchmark_pixels_div1280_ = static_cast<int>(( 188 static_cast<double>(Abs(benchmark_width_)) * 189 static_cast<double>(Abs(benchmark_height_)) * 190 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 191 } 192 193 LibYUVRotateTest::LibYUVRotateTest() : 194 benchmark_iterations_(BENCHMARK_ITERATIONS), benchmark_width_(128), 195 benchmark_height_(72), disable_cpu_flags_(1), benchmark_cpu_info_(-1) { 196 const char* repeat = getenv("LIBYUV_REPEAT"); 197 if (repeat) { 198 benchmark_iterations_ = atoi(repeat); // NOLINT 199 } 200 if (FLAGS_libyuv_repeat) { 201 benchmark_iterations_ = FLAGS_libyuv_repeat; 202 } 203 if (benchmark_iterations_ > 1) { 204 benchmark_width_ = 1280; 205 benchmark_height_ = 720; 206 } 207 const char* width = getenv("LIBYUV_WIDTH"); 208 if (width) { 209 benchmark_width_ = atoi(width); // NOLINT 210 } 211 if (FLAGS_libyuv_width) { 212 benchmark_width_ = FLAGS_libyuv_width; 213 } 214 const char* height = getenv("LIBYUV_HEIGHT"); 215 if (height) { 216 benchmark_height_ = atoi(height); // NOLINT 217 } 218 if (FLAGS_libyuv_height) { 219 benchmark_height_ = FLAGS_libyuv_height; 220 } 221 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 222 if (cpu_flags) { 223 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 224 } 225 if (FLAGS_libyuv_flags) { 226 disable_cpu_flags_ = FLAGS_libyuv_flags; 227 } 228 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 229 if (cpu_info) { 230 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 231 } 232 if (FLAGS_libyuv_cpu_info) { 233 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 234 } 235 benchmark_pixels_div256_ = static_cast<int>(( 236 static_cast<double>(Abs(benchmark_width_)) * 237 static_cast<double>(Abs(benchmark_height_)) * 238 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 239 benchmark_pixels_div1280_ = static_cast<int>(( 240 static_cast<double>(Abs(benchmark_width_)) * 241 static_cast<double>(Abs(benchmark_height_)) * 242 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 243 } 244 245 LibYUVPlanarTest::LibYUVPlanarTest() : 246 benchmark_iterations_(BENCHMARK_ITERATIONS), benchmark_width_(128), 247 benchmark_height_(72), disable_cpu_flags_(1), benchmark_cpu_info_(-1) { 248 const char* repeat = getenv("LIBYUV_REPEAT"); 249 if (repeat) { 250 benchmark_iterations_ = atoi(repeat); // NOLINT 251 } 252 if (FLAGS_libyuv_repeat) { 253 benchmark_iterations_ = FLAGS_libyuv_repeat; 254 } 255 if (benchmark_iterations_ > 1) { 256 benchmark_width_ = 1280; 257 benchmark_height_ = 720; 258 } 259 const char* width = getenv("LIBYUV_WIDTH"); 260 if (width) { 261 benchmark_width_ = atoi(width); // NOLINT 262 } 263 if (FLAGS_libyuv_width) { 264 benchmark_width_ = FLAGS_libyuv_width; 265 } 266 const char* height = getenv("LIBYUV_HEIGHT"); 267 if (height) { 268 benchmark_height_ = atoi(height); // NOLINT 269 } 270 if (FLAGS_libyuv_height) { 271 benchmark_height_ = FLAGS_libyuv_height; 272 } 273 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 274 if (cpu_flags) { 275 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 276 } 277 if (FLAGS_libyuv_flags) { 278 disable_cpu_flags_ = FLAGS_libyuv_flags; 279 } 280 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 281 if (cpu_info) { 282 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 283 } 284 if (FLAGS_libyuv_cpu_info) { 285 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 286 } 287 benchmark_pixels_div256_ = static_cast<int>(( 288 static_cast<double>(Abs(benchmark_width_)) * 289 static_cast<double>(Abs(benchmark_height_)) * 290 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 291 benchmark_pixels_div1280_ = static_cast<int>(( 292 static_cast<double>(Abs(benchmark_width_)) * 293 static_cast<double>(Abs(benchmark_height_)) * 294 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 295 } 296 297 LibYUVBaseTest::LibYUVBaseTest() : 298 benchmark_iterations_(BENCHMARK_ITERATIONS), benchmark_width_(128), 299 benchmark_height_(72), disable_cpu_flags_(1), benchmark_cpu_info_(-1) { 300 const char* repeat = getenv("LIBYUV_REPEAT"); 301 if (repeat) { 302 benchmark_iterations_ = atoi(repeat); // NOLINT 303 } 304 if (FLAGS_libyuv_repeat) { 305 benchmark_iterations_ = FLAGS_libyuv_repeat; 306 } 307 if (benchmark_iterations_ > 1) { 308 benchmark_width_ = 1280; 309 benchmark_height_ = 720; 310 } 311 const char* width = getenv("LIBYUV_WIDTH"); 312 if (width) { 313 benchmark_width_ = atoi(width); // NOLINT 314 } 315 if (FLAGS_libyuv_width) { 316 benchmark_width_ = FLAGS_libyuv_width; 317 } 318 const char* height = getenv("LIBYUV_HEIGHT"); 319 if (height) { 320 benchmark_height_ = atoi(height); // NOLINT 321 } 322 if (FLAGS_libyuv_height) { 323 benchmark_height_ = FLAGS_libyuv_height; 324 } 325 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 326 if (cpu_flags) { 327 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 328 } 329 if (FLAGS_libyuv_flags) { 330 disable_cpu_flags_ = FLAGS_libyuv_flags; 331 } 332 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 333 if (cpu_info) { 334 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 335 } 336 if (FLAGS_libyuv_cpu_info) { 337 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 338 } 339 benchmark_pixels_div256_ = static_cast<int>(( 340 static_cast<double>(Abs(benchmark_width_)) * 341 static_cast<double>(Abs(benchmark_height_)) * 342 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 343 benchmark_pixels_div1280_ = static_cast<int>(( 344 static_cast<double>(Abs(benchmark_width_)) * 345 static_cast<double>(Abs(benchmark_height_)) * 346 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 347 } 348 349 int main(int argc, char** argv) { 350 ::testing::InitGoogleTest(&argc, argv); 351 // AllowCommandLineParsing allows us to ignore flags passed on to us by 352 // Chromium build bots without having to explicitly disable them. 353 google::AllowCommandLineReparsing(); 354 google::ParseCommandLineFlags(&argc, &argv, true); 355 return RUN_ALL_TESTS(); 356 } 357