Index: mojo/public/tests/test_support.cc |
diff --git a/mojo/public/tests/test_support.cc b/mojo/public/tests/test_support.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0140c9f6b76cbea7bdb17c3f85fa0136dece81d5 |
--- /dev/null |
+++ b/mojo/public/tests/test_support.cc |
@@ -0,0 +1,48 @@ |
+// 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 "mojo/public/tests/test_support.h" |
+ |
+#include "base/test/perf_log.h" |
+#include "base/time/time.h" |
+#include "mojo/system/core_impl.h" |
+ |
+namespace mojo { |
+namespace test { |
+ |
+TestBase::TestBase() { |
+} |
+ |
+TestBase::~TestBase() { |
+} |
+ |
+void TestBase::SetUp() { |
+ if (!system::CoreImpl::Get()) |
+ system::CoreImpl::Init(); |
+} |
+ |
+void IterateAndReportPerf(const char* test_name, |
+ base::Callback<void()> single_iteration) { |
+ // TODO(vtl): These should be specifiable using command-line flags. |
+ static const size_t kGranularity = 100; |
+ static const double kPerftestTimeSeconds = 3.0; |
+ |
+ const base::TimeTicks start_time = base::TimeTicks::HighResNow(); |
+ base::TimeTicks end_time; |
+ size_t iterations = 0; |
+ do { |
+ for (size_t i = 0; i < kGranularity; i++) |
+ single_iteration.Run(); |
+ iterations += kGranularity; |
+ |
+ end_time = base::TimeTicks::HighResNow(); |
+ } while ((end_time - start_time).InSecondsF() < kPerftestTimeSeconds); |
+ |
+ base::LogPerfResult(test_name, |
+ iterations / (end_time - start_time).InSecondsF(), |
+ "iterations/second"); |
+} |
+ |
+} // namespace test |
+} // namespace mojo |