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

Unified Diff: media/base/vector_math_perftest.cc

Issue 41633002: Port SincResampler's ConvolveBenchmark, as well as VectorMath's benchmarks to media_perftests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@portbus
Patch Set: Add vector math port. Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: media/base/vector_math_perftest.cc
diff --git a/media/base/vector_math_perftest.cc b/media/base/vector_math_perftest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d4e23707d4b558c88a067de61e05a12fce6129f3
--- /dev/null
+++ b/media/base/vector_math_perftest.cc
@@ -0,0 +1,134 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/cpu.h"
+#include "base/memory/aligned_memory.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "media/base/vector_math.h"
+#include "media/base/vector_math_testing.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/perf/perf_test.h"
+
+// Default test values.
+static const float kScale = 0.5;
+static const float kInputFillValue = 1.0;
+static const float kOutputFillValue = 3.0;
+
+using base::TimeTicks;
+using std::fill;
+
+namespace media {
+
+static const int kBenchmarkIterations = 200000;
+
+class VectorMathPerfTest : public testing::Test {
+ public:
+ static const int kVectorSize = 8192;
+
+ VectorMathPerfTest() {
+ // Initialize input and output vectors.
+ input_vector.reset(static_cast<float*>(base::AlignedAlloc(
+ sizeof(float) * kVectorSize, vector_math::kRequiredAlignment)));
+ output_vector.reset(static_cast<float*>(base::AlignedAlloc(
+ sizeof(float) * kVectorSize, vector_math::kRequiredAlignment)));
+ }
+
+ void FillTestVectors(float input, float output) {
+ // Setup input and output vectors.
+ fill(input_vector.get(), input_vector.get() + kVectorSize, input);
+ fill(output_vector.get(), output_vector.get() + kVectorSize, output);
+ }
+
+ void RunBenchmark(void (*fn)(const float[], float, int, float[]),
+ bool aligned,
+ const std::string& test_name,
+ const std::string& trace_name) {
+ FillTestVectors(kInputFillValue, kOutputFillValue);
+ TimeTicks start = TimeTicks::HighResNow();
+ for (int i = 0; i < kBenchmarkIterations; ++i) {
+ fn(input_vector.get(),
+ kScale,
+ kVectorSize - (aligned ? 0 : 1),
+ output_vector.get());
+ }
+ double total_time_seconds = (TimeTicks::HighResNow() - start).InSecondsF();
+ perf_test::PrintResult(test_name,
+ "",
+ trace_name,
+ kBenchmarkIterations / total_time_seconds,
+ "runs/s",
+ true);
+ }
+
+ protected:
+ scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> input_vector;
+ scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> output_vector;
+
+ DISALLOW_COPY_AND_ASSIGN(VectorMathPerfTest);
+};
+
+// Define platform independent function name for FMAC* perf tests.
+#if defined(ARCH_CPU_X86_FAMILY)
+#define FMAC_FUNC FMAC_SSE
+#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
+#define FMAC_FUNC FMAC_NEON
+#endif
+
+// Benchmark for each optimized vector_math::FMAC() method.
+TEST_F(VectorMathPerfTest, FMAC) {
+ // Benchmark FMAC_C().
+ RunBenchmark(
+ vector_math::FMAC_C, true, "vector_math_fmac", "unoptimized");
+#if defined(FMAC_FUNC)
+#if defined(ARCH_CPU_X86_FAMILY)
+ ASSERT_TRUE(base::CPU().has_sse());
+#endif
+ // Benchmark FMAC_FUNC() with unaligned size.
+ ASSERT_NE((kVectorSize - 1) % (vector_math::kRequiredAlignment /
+ sizeof(float)), 0U);
scherkus (not reviewing) 2013/10/29 00:13:45 indent here should be aligned at (
+ RunBenchmark(
+ vector_math::FMAC_FUNC, false, "vector_math_fmac", "optimized_unaligned");
+ // Benchmark FMAC_FUNC() with aligned size.
+ ASSERT_EQ(kVectorSize % (vector_math::kRequiredAlignment / sizeof(float)),
+ 0U);
+ RunBenchmark(
+ vector_math::FMAC_FUNC, true, "vector_math_fmac", "optimized_aligned");
+#endif
+}
+
+#undef FMAC_FUNC
+
+// Define platform independent function name for FMULBenchmark* tests.
+#if defined(ARCH_CPU_X86_FAMILY)
+#define FMUL_FUNC FMUL_SSE
+#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
+#define FMUL_FUNC FMUL_NEON
+#endif
+
+// Benchmark for each optimized vector_math::FMUL() method.
+TEST_F(VectorMathPerfTest, FMUL) {
+ // Benchmark FMUL_C().
+ RunBenchmark(
+ vector_math::FMUL_C, true, "vector_math_fmul", "unoptimized");
+#if defined(FMUL_FUNC)
+#if defined(ARCH_CPU_X86_FAMILY)
+ ASSERT_TRUE(base::CPU().has_sse());
+#endif
+ // Benchmark FMUL_FUNC() with unaligned size.
+ ASSERT_NE((kVectorSize - 1) % (vector_math::kRequiredAlignment /
+ sizeof(float)), 0U);
scherkus (not reviewing) 2013/10/29 00:13:45 ditto
+ RunBenchmark(
+ vector_math::FMUL_FUNC, false, "vector_math_fmac", "optimized_unaligned");
+ // Benchmark FMUL_FUNC() with aligned size.
+ ASSERT_EQ(kVectorSize % (vector_math::kRequiredAlignment / sizeof(float)),
+ 0U);
+ RunBenchmark(
+ vector_math::FMUL_FUNC, true, "vector_math_fmac", "optimized_aligned");
+#endif
+}
+
+#undef FMUL_FUNC
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698