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 "gtest/gtest.h" | 5 #include "gtest/gtest.h" |
6 #include "mojo/public/cpp/bindings/binding.h" | 6 #include "mojo/public/cpp/bindings/binding.h" |
7 #include "mojo/public/cpp/test_support/test_support.h" | 7 #include "mojo/public/cpp/test_support/test_support.h" |
8 #include "mojo/public/cpp/utility/run_loop.h" | 8 #include "mojo/public/cpp/utility/run_loop.h" |
9 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" | 9 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 void OnPingDone(); | 43 void OnPingDone(); |
44 | 44 |
45 test::PingServicePtr service_; | 45 test::PingServicePtr service_; |
46 unsigned int iterations_to_run_; | 46 unsigned int iterations_to_run_; |
47 unsigned int current_iterations_; | 47 unsigned int current_iterations_; |
48 | 48 |
49 MOJO_DISALLOW_COPY_AND_ASSIGN(PingPongTest); | 49 MOJO_DISALLOW_COPY_AND_ASSIGN(PingPongTest); |
50 }; | 50 }; |
51 | 51 |
52 PingPongTest::PingPongTest(test::PingServicePtr service) | 52 PingPongTest::PingPongTest(test::PingServicePtr service) |
53 : service_(service.Pass()) { | 53 : service_(service.Pass()) {} |
54 } | |
55 | 54 |
56 void PingPongTest::Run(unsigned int iterations) { | 55 void PingPongTest::Run(unsigned int iterations) { |
57 iterations_to_run_ = iterations; | 56 iterations_to_run_ = iterations; |
58 current_iterations_ = 0; | 57 current_iterations_ = 0; |
59 | 58 |
60 service_->Ping([this]() { OnPingDone(); }); | 59 service_->Ping([this]() { OnPingDone(); }); |
61 RunLoop::current()->Run(); | 60 RunLoop::current()->Run(); |
62 } | 61 } |
63 | 62 |
64 void PingPongTest::OnPingDone() { | 63 void PingPongTest::OnPingDone() { |
65 current_iterations_++; | 64 current_iterations_++; |
66 if (current_iterations_ >= iterations_to_run_) { | 65 if (current_iterations_ >= iterations_to_run_) { |
67 RunLoop::current()->Quit(); | 66 RunLoop::current()->Quit(); |
68 return; | 67 return; |
69 } | 68 } |
70 | 69 |
71 service_->Ping([this]() { OnPingDone(); }); | 70 service_->Ping([this]() { OnPingDone(); }); |
72 } | 71 } |
73 | 72 |
74 struct BoundPingService { | 73 struct BoundPingService { |
75 BoundPingService() : binding(&impl) { | 74 BoundPingService() : binding(&impl) { binding.Bind(GetProxy(&service)); } |
76 binding.Bind(GetProxy(&service)); | |
77 } | |
78 | 75 |
79 PingServiceImpl impl; | 76 PingServiceImpl impl; |
80 test::PingServicePtr service; | 77 test::PingServicePtr service; |
81 Binding<test::PingService> binding; | 78 Binding<test::PingService> binding; |
82 }; | 79 }; |
83 | 80 |
84 class MojoBindingsPerftest : public testing::Test { | 81 class MojoBindingsPerftest : public testing::Test { |
85 protected: | 82 protected: |
86 RunLoop run_loop_; | 83 RunLoop run_loop_; |
87 }; | 84 }; |
88 | 85 |
89 TEST_F(MojoBindingsPerftest, InProcessPingPong) { | 86 TEST_F(MojoBindingsPerftest, InProcessPingPong) { |
90 test::PingServicePtr service; | 87 test::PingServicePtr service; |
91 PingServiceImpl impl; | 88 PingServiceImpl impl; |
92 Binding<test::PingService> binding(&impl, GetProxy(&service)); | 89 Binding<test::PingService> binding(&impl, GetProxy(&service)); |
93 PingPongTest test(service.Pass()); | 90 PingPongTest test(service.Pass()); |
94 | 91 |
95 { | 92 { |
96 const unsigned int kIterations = 100000; | 93 const unsigned int kIterations = 100000; |
97 const MojoTimeTicks start_time = MojoGetTimeTicksNow(); | 94 const MojoTimeTicks start_time = MojoGetTimeTicksNow(); |
98 test.Run(kIterations); | 95 test.Run(kIterations); |
99 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); | 96 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); |
100 test::LogPerfResult( | 97 test::LogPerfResult("InProcessPingPong", "0_Inactive", |
101 "InProcessPingPong", "0_Inactive", | 98 kIterations / MojoTicksToSeconds(end_time - start_time), |
102 kIterations / MojoTicksToSeconds(end_time - start_time), | 99 "pings/second"); |
103 "pings/second"); | |
104 } | 100 } |
105 | 101 |
106 { | 102 { |
107 const size_t kNumInactiveServices = 1000; | 103 const size_t kNumInactiveServices = 1000; |
108 BoundPingService* inactive_services = | 104 BoundPingService* inactive_services = |
109 new BoundPingService[kNumInactiveServices]; | 105 new BoundPingService[kNumInactiveServices]; |
110 | 106 |
111 const unsigned int kIterations = 10000; | 107 const unsigned int kIterations = 10000; |
112 const MojoTimeTicks start_time = MojoGetTimeTicksNow(); | 108 const MojoTimeTicks start_time = MojoGetTimeTicksNow(); |
113 test.Run(kIterations); | 109 test.Run(kIterations); |
114 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); | 110 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); |
115 test::LogPerfResult( | 111 test::LogPerfResult("InProcessPingPong", "1000_Inactive", |
116 "InProcessPingPong", "1000_Inactive", | 112 kIterations / MojoTicksToSeconds(end_time - start_time), |
117 kIterations / MojoTicksToSeconds(end_time - start_time), | 113 "pings/second"); |
118 "pings/second"); | |
119 | 114 |
120 delete[] inactive_services; | 115 delete[] inactive_services; |
121 } | 116 } |
122 } | 117 } |
123 | 118 |
124 } // namespace | 119 } // namespace |
125 } // namespace mojo | 120 } // namespace mojo |
OLD | NEW |