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 // This file has perf tests for async waits using |mojo::RunLoop| (i.e., the |
| 6 // "standalone" |Environment|). |
| 7 |
| 8 #include <stdio.h> |
| 9 |
| 10 #include "mojo/public/c/environment/tests/async_waiter_perftest_helpers.h" |
| 11 #include "mojo/public/cpp/environment/environment.h" |
| 12 #include "mojo/public/cpp/test_support/test_support.h" |
| 13 #include "mojo/public/cpp/utility/run_loop.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace mojo { |
| 17 namespace { |
| 18 |
| 19 constexpr MojoTimeTicks kPerftestTimeMicroseconds = 3 * 1000000; |
| 20 |
| 21 TEST(RunLoopAsyncWaitPerftest, SingleThreaded) { |
| 22 for (uint32_t num_handles = 1u; num_handles <= 10000u; num_handles *= 10u) { |
| 23 RunLoop run_loop; |
| 24 |
| 25 MojoTimeTicks start_time = 0; |
| 26 MojoTimeTicks end_time = 0; |
| 27 uint64_t raw_result = test::DoAsyncWaiterPerfTest( |
| 28 Environment::GetDefaultAsyncWaiter(), num_handles, |
| 29 [&start_time, &end_time]() { |
| 30 RunLoop::current()->PostDelayedTask( |
| 31 []() { RunLoop::current()->Quit(); }, kPerftestTimeMicroseconds); |
| 32 start_time = MojoGetTimeTicksNow(); |
| 33 RunLoop::current()->Run(); |
| 34 end_time = MojoGetTimeTicksNow(); |
| 35 }); |
| 36 |
| 37 double result = static_cast<double>(raw_result) / |
| 38 (static_cast<double>(end_time - start_time) / 1000000.0); |
| 39 char sub_test_name[100] = {}; |
| 40 sprintf(sub_test_name, "%u", static_cast<unsigned>(num_handles)); |
| 41 test::LogPerfResult("RunLoopAsyncWaitPerftest.SingleThreaded", |
| 42 sub_test_name, result, "callbacks/second"); |
| 43 } |
| 44 } |
| 45 |
| 46 } // namespace |
| 47 } // namespace mojo |
OLD | NEW |