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 |base::MessageLoop| (i.e., the |
| 6 // "Chromium" |Environment|). |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <functional> |
| 11 #include <memory> |
| 12 |
| 13 #include "base/bind.h" |
| 14 #include "base/location.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/test/perf_log.h" |
| 19 #include "base/time/time.h" |
| 20 #include "mojo/message_pump/message_pump_mojo.h" |
| 21 #include "mojo/public/c/environment/tests/async_waiter_perftest_helpers.h" |
| 22 #include "mojo/public/cpp/environment/environment.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 |
| 25 namespace mojo { |
| 26 namespace { |
| 27 |
| 28 constexpr int64_t kPerftestTimeMicroseconds = 3 * 1000000; |
| 29 |
| 30 void QuitMessageLoopNow() { |
| 31 base::MessageLoop::current()->QuitNow(); |
| 32 } |
| 33 |
| 34 void SingleThreadedTestHelper( |
| 35 const char* name, |
| 36 std::function<std::unique_ptr<base::MessageLoop>()> make_message_loop) { |
| 37 for (uint32_t num_handles = 1u; num_handles <= 10000u; num_handles *= 10u) { |
| 38 auto message_loop = make_message_loop(); |
| 39 |
| 40 base::TimeTicks start_time; |
| 41 base::TimeTicks end_time; |
| 42 uint64_t raw_result = test::DoAsyncWaiterPerfTest( |
| 43 Environment::GetDefaultAsyncWaiter(), num_handles, |
| 44 [&start_time, &end_time]() { |
| 45 base::MessageLoop::current()->PostDelayedTask( |
| 46 FROM_HERE, base::Bind(&QuitMessageLoopNow), |
| 47 base::TimeDelta::FromMicroseconds(kPerftestTimeMicroseconds)); |
| 48 start_time = base::TimeTicks::Now(); |
| 49 base::MessageLoop::current()->Run(); |
| 50 end_time = base::TimeTicks::Now(); |
| 51 }); |
| 52 |
| 53 double result = |
| 54 static_cast<double>(raw_result) / (end_time - start_time).InSecondsF(); |
| 55 base::LogPerfResult( |
| 56 base::StringPrintf("%s/%u", name, static_cast<unsigned>(num_handles)) |
| 57 .c_str(), |
| 58 result, "callbacks/second"); |
| 59 } |
| 60 } |
| 61 |
| 62 TEST(AsyncWaitPerfTest, SingleThreaded_DefaultMessagePump) { |
| 63 SingleThreadedTestHelper( |
| 64 "AsyncWaitPerfTest.SingleThreaded_DefaultMessagePump", []() { |
| 65 return std::unique_ptr<base::MessageLoop>(new base::MessageLoop()); |
| 66 }); |
| 67 } |
| 68 |
| 69 TEST(AsyncWaitPerfTest, SingleThreaded_MessagePumpMojo) { |
| 70 SingleThreadedTestHelper( |
| 71 "AsyncWaitPerfTest.SingleThreaded_MessagePumpMojo", []() { |
| 72 return std::unique_ptr<base::MessageLoop>(new base::MessageLoop( |
| 73 make_scoped_ptr(new common::MessagePumpMojo()))); |
| 74 }); |
| 75 } |
| 76 |
| 77 } // namespace |
| 78 } // namespace mojo |
OLD | NEW |