| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <utility> |
| 6 | 7 |
| 7 #include "mojo/public/cpp/bindings/binding.h" | 8 #include "mojo/public/cpp/bindings/binding.h" |
| 8 #include "mojo/public/cpp/test_support/test_support.h" | 9 #include "mojo/public/cpp/test_support/test_support.h" |
| 9 #include "mojo/public/cpp/test_support/test_utils.h" | 10 #include "mojo/public/cpp/test_support/test_utils.h" |
| 10 #include "mojo/public/cpp/utility/run_loop.h" | 11 #include "mojo/public/cpp/utility/run_loop.h" |
| 11 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" | 12 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace mojo { | 15 namespace mojo { |
| 15 namespace { | 16 namespace { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 46 void OnPingDone(); | 47 void OnPingDone(); |
| 47 | 48 |
| 48 test::PingServicePtr service_; | 49 test::PingServicePtr service_; |
| 49 unsigned int iterations_to_run_; | 50 unsigned int iterations_to_run_; |
| 50 unsigned int current_iterations_; | 51 unsigned int current_iterations_; |
| 51 | 52 |
| 52 MOJO_DISALLOW_COPY_AND_ASSIGN(PingPongTest); | 53 MOJO_DISALLOW_COPY_AND_ASSIGN(PingPongTest); |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 PingPongTest::PingPongTest(test::PingServicePtr service) | 56 PingPongTest::PingPongTest(test::PingServicePtr service) |
| 56 : service_(service.Pass()) { | 57 : service_(std::move(service)) {} |
| 57 } | |
| 58 | 58 |
| 59 void PingPongTest::Run(unsigned int iterations) { | 59 void PingPongTest::Run(unsigned int iterations) { |
| 60 iterations_to_run_ = iterations; | 60 iterations_to_run_ = iterations; |
| 61 current_iterations_ = 0; | 61 current_iterations_ = 0; |
| 62 | 62 |
| 63 service_->Ping([this]() { OnPingDone(); }); | 63 service_->Ping([this]() { OnPingDone(); }); |
| 64 RunLoop::current()->Run(); | 64 RunLoop::current()->Run(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void PingPongTest::OnPingDone() { | 67 void PingPongTest::OnPingDone() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 87 class MojoBindingsPerftest : public testing::Test { | 87 class MojoBindingsPerftest : public testing::Test { |
| 88 protected: | 88 protected: |
| 89 Environment env_; | 89 Environment env_; |
| 90 RunLoop run_loop_; | 90 RunLoop run_loop_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 TEST_F(MojoBindingsPerftest, InProcessPingPong) { | 93 TEST_F(MojoBindingsPerftest, InProcessPingPong) { |
| 94 test::PingServicePtr service; | 94 test::PingServicePtr service; |
| 95 PingServiceImpl impl; | 95 PingServiceImpl impl; |
| 96 Binding<test::PingService> binding(&impl, GetProxy(&service)); | 96 Binding<test::PingService> binding(&impl, GetProxy(&service)); |
| 97 PingPongTest test(service.Pass()); | 97 PingPongTest test(std::move(service)); |
| 98 | 98 |
| 99 { | 99 { |
| 100 const unsigned int kIterations = 100000; | 100 const unsigned int kIterations = 100000; |
| 101 const MojoTimeTicks start_time = MojoGetTimeTicksNow(); | 101 const MojoTimeTicks start_time = MojoGetTimeTicksNow(); |
| 102 test.Run(kIterations); | 102 test.Run(kIterations); |
| 103 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); | 103 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); |
| 104 test::LogPerfResult( | 104 test::LogPerfResult( |
| 105 "InProcessPingPong", "0_Inactive", | 105 "InProcessPingPong", "0_Inactive", |
| 106 kIterations / MojoTicksToSeconds(end_time - start_time), | 106 kIterations / MojoTicksToSeconds(end_time - start_time), |
| 107 "pings/second"); | 107 "pings/second"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 120 "InProcessPingPong", "1000_Inactive", | 120 "InProcessPingPong", "1000_Inactive", |
| 121 kIterations / MojoTicksToSeconds(end_time - start_time), | 121 kIterations / MojoTicksToSeconds(end_time - start_time), |
| 122 "pings/second"); | 122 "pings/second"); |
| 123 | 123 |
| 124 delete[] inactive_services; | 124 delete[] inactive_services; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace | 128 } // namespace |
| 129 } // namespace mojo | 129 } // namespace mojo |
| OLD | NEW |