blob: 0140c9f6b76cbea7bdb17c3f85fa0136dece81d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
|