| OLD | NEW |
| (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 | |
| OLD | NEW |