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 "mojo/public/tests/test_support.h" |
| 6 |
| 7 #include "base/test/perf_log.h" |
| 8 #include "base/time/time.h" |
| 9 #include "mojo/system/core_impl.h" |
| 10 |
| 11 namespace mojo { |
| 12 namespace test { |
| 13 |
| 14 TestBase::TestBase() { |
| 15 } |
| 16 |
| 17 TestBase::~TestBase() { |
| 18 } |
| 19 |
| 20 void TestBase::SetUp() { |
| 21 if (!system::CoreImpl::Get()) |
| 22 system::CoreImpl::Init(); |
| 23 } |
| 24 |
| 25 void IterateAndReportPerf(const char* test_name, |
| 26 base::Callback<void()> single_iteration) { |
| 27 // TODO(vtl): These should be specifiable using command-line flags. |
| 28 static const size_t kGranularity = 100; |
| 29 static const double kPerftestTimeSeconds = 3.0; |
| 30 |
| 31 const base::TimeTicks start_time = base::TimeTicks::HighResNow(); |
| 32 base::TimeTicks end_time; |
| 33 size_t iterations = 0; |
| 34 do { |
| 35 for (size_t i = 0; i < kGranularity; i++) |
| 36 single_iteration.Run(); |
| 37 iterations += kGranularity; |
| 38 |
| 39 end_time = base::TimeTicks::HighResNow(); |
| 40 } while ((end_time - start_time).InSecondsF() < kPerftestTimeSeconds); |
| 41 |
| 42 base::LogPerfResult(test_name, |
| 43 iterations / (end_time - start_time).InSecondsF(), |
| 44 "iterations/second"); |
| 45 } |
| 46 |
| 47 } // namespace test |
| 48 } // namespace mojo |
OLD | NEW |