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

Side by Side Diff: mojo/public/c/tests/system/perftest_utils.cc

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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/c/tests/system/perftest_utils.h"
6
7 #include <assert.h>
8 #include <mojo/macros.h>
9 #include <mojo/system/time.h>
10 #include <stddef.h>
11 #include <time.h>
12
13 #include "mojo/public/cpp/test_support/test_support.h"
14
15 namespace mojo {
16 namespace test {
17
18 // Iterates the given function for |kPerftestTimeMicroseconds| and reports the
19 // number of iterations executed per second.
20 void IterateAndReportPerf(const char* test_name,
21 const char* sub_test_name,
22 std::function<void()> single_iteration) {
23 // TODO(vtl): These should be specifiable using command-line flags.
24 static constexpr size_t kGranularity = 100u;
25
26 const MojoTimeTicks start_time = MojoGetTimeTicksNow();
27 MojoTimeTicks end_time;
28 size_t iterations = 0u;
29 do {
30 for (size_t i = 0u; i < kGranularity; i++)
31 single_iteration();
32 iterations += kGranularity;
33
34 end_time = MojoGetTimeTicksNow();
35 } while (end_time - start_time < kPerftestTimeMicroseconds);
36
37 LogPerfResult(test_name, sub_test_name,
38 1000000.0 * iterations / (end_time - start_time),
39 "iterations/second");
40 }
41
42 void Sleep(MojoTimeTicks microseconds) {
43 struct timespec req = {
44 static_cast<time_t>(microseconds / 1000000), // Seconds.
45 static_cast<long>(microseconds % 1000000) * 1000L // Nanoseconds.
46 };
47 int rv = nanosleep(&req, nullptr);
48 MOJO_ALLOW_UNUSED_LOCAL(rv);
49 assert(rv == 0);
50 }
51
52 } // namespace test
53 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/c/tests/system/perftest_utils.h ('k') | mojo/public/c/tests/system/reference_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698