| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/public/tests/test_support.h" | 5 #include "mojo/public/tests/test_support.h" |
| 6 | 6 |
| 7 #include "base/test/perf_log.h" | 7 #include "base/test/perf_log.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "mojo/system/core_impl.h" | 9 #include "mojo/system/core_impl.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 namespace test { | 12 namespace test { |
| 13 | 13 |
| 14 TestBase::TestBase() { | 14 TestBase::TestBase() { |
| 15 if (!system::CoreImpl::Get()) |
| 16 system::CoreImpl::Init(); |
| 15 } | 17 } |
| 16 | 18 |
| 17 TestBase::~TestBase() { | 19 TestBase::~TestBase() { |
| 18 } | 20 } |
| 19 | 21 |
| 20 void TestBase::SetUp() { | |
| 21 if (!system::CoreImpl::Get()) | |
| 22 system::CoreImpl::Init(); | |
| 23 } | |
| 24 | |
| 25 void IterateAndReportPerf(const char* test_name, | 22 void IterateAndReportPerf(const char* test_name, |
| 26 base::Callback<void()> single_iteration) { | 23 base::Callback<void()> single_iteration) { |
| 27 // TODO(vtl): These should be specifiable using command-line flags. | 24 // TODO(vtl): These should be specifiable using command-line flags. |
| 28 static const size_t kGranularity = 100; | 25 static const size_t kGranularity = 100; |
| 29 static const double kPerftestTimeSeconds = 3.0; | 26 static const double kPerftestTimeSeconds = 3.0; |
| 30 | 27 |
| 31 const base::TimeTicks start_time = base::TimeTicks::HighResNow(); | 28 const base::TimeTicks start_time = base::TimeTicks::HighResNow(); |
| 32 base::TimeTicks end_time; | 29 base::TimeTicks end_time; |
| 33 size_t iterations = 0; | 30 size_t iterations = 0; |
| 34 do { | 31 do { |
| 35 for (size_t i = 0; i < kGranularity; i++) | 32 for (size_t i = 0; i < kGranularity; i++) |
| 36 single_iteration.Run(); | 33 single_iteration.Run(); |
| 37 iterations += kGranularity; | 34 iterations += kGranularity; |
| 38 | 35 |
| 39 end_time = base::TimeTicks::HighResNow(); | 36 end_time = base::TimeTicks::HighResNow(); |
| 40 } while ((end_time - start_time).InSecondsF() < kPerftestTimeSeconds); | 37 } while ((end_time - start_time).InSecondsF() < kPerftestTimeSeconds); |
| 41 | 38 |
| 42 base::LogPerfResult(test_name, | 39 base::LogPerfResult(test_name, |
| 43 iterations / (end_time - start_time).InSecondsF(), | 40 iterations / (end_time - start_time).InSecondsF(), |
| 44 "iterations/second"); | 41 "iterations/second"); |
| 45 } | 42 } |
| 46 | 43 |
| 47 } // namespace test | 44 } // namespace test |
| 48 } // namespace mojo | 45 } // namespace mojo |
| OLD | NEW |