Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: mojo/public/cpp/bindings/tests/bindings_perftest.cc

Issue 2532053004: Mojo C++ bindings: remove the single-threaded Router. (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "mojo/public/cpp/bindings/binding.h" 12 #include "mojo/public/cpp/bindings/binding.h"
13 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" 13 #include "mojo/public/cpp/bindings/interface_endpoint_client.h"
14 #include "mojo/public/cpp/bindings/lib/message_builder.h" 14 #include "mojo/public/cpp/bindings/lib/message_builder.h"
15 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 15 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
16 #include "mojo/public/cpp/bindings/lib/router.h"
17 #include "mojo/public/cpp/bindings/message.h" 16 #include "mojo/public/cpp/bindings/message.h"
18 #include "mojo/public/cpp/test_support/test_support.h" 17 #include "mojo/public/cpp/test_support/test_support.h"
19 #include "mojo/public/cpp/test_support/test_utils.h" 18 #include "mojo/public/cpp/test_support/test_utils.h"
20 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" 19 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 21
23 namespace mojo { 22 namespace mojo {
24 namespace { 23 namespace {
25 24
26 const double kMojoTicksPerSecond = 1000000.0; 25 const double kMojoTicksPerSecond = 1000000.0;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 184 }
186 185
187 private: 186 private:
188 base::TimeTicks start_time_; 187 base::TimeTicks start_time_;
189 base::TimeTicks end_time_; 188 base::TimeTicks end_time_;
190 uint32_t expected_count_ = 0; 189 uint32_t expected_count_ = 0;
191 MessageReceiver* sender_; 190 MessageReceiver* sender_;
192 base::Closure quit_closure_; 191 base::Closure quit_closure_;
193 }; 192 };
194 193
195 TEST_F(MojoBindingsPerftest, RouterPingPong) {
196 MessagePipe pipe;
197 internal::Router router0(std::move(pipe.handle0), FilterChain(), false,
198 base::ThreadTaskRunnerHandle::Get(), 0u);
199 internal::Router router1(std::move(pipe.handle1), FilterChain(), false,
200 base::ThreadTaskRunnerHandle::Get(), 0u);
201 PingPongPaddle paddle0(&router0);
202 router0.set_incoming_receiver(&paddle0);
203 PingPongPaddle paddle1(&router1);
204 router1.set_incoming_receiver(&paddle1);
205
206 static const uint32_t kWarmUpIterations = 1000;
207 static const uint32_t kTestIterations = 1000000;
208
209 paddle0.Serve(kWarmUpIterations);
210
211 base::TimeDelta duration = paddle0.Serve(kTestIterations);
212
213 test::LogPerfResult("RouterPingPong", nullptr,
214 kTestIterations / duration.InSecondsF(), "pings/second");
215 }
216
217 TEST_F(MojoBindingsPerftest, MultiplexRouterPingPong) { 194 TEST_F(MojoBindingsPerftest, MultiplexRouterPingPong) {
218 MessagePipe pipe; 195 MessagePipe pipe;
219 scoped_refptr<internal::MultiplexRouter> router0( 196 scoped_refptr<internal::MultiplexRouter> router0(
220 new internal::MultiplexRouter(std::move(pipe.handle0), 197 new internal::MultiplexRouter(std::move(pipe.handle0),
221 internal::MultiplexRouter::SINGLE_INTERFACE, 198 internal::MultiplexRouter::SINGLE_INTERFACE,
222 true, base::ThreadTaskRunnerHandle::Get())); 199 true, base::ThreadTaskRunnerHandle::Get()));
223 scoped_refptr<internal::MultiplexRouter> router1( 200 scoped_refptr<internal::MultiplexRouter> router1(
224 new internal::MultiplexRouter( 201 new internal::MultiplexRouter(
225 std::move(pipe.handle1), internal::MultiplexRouter::SINGLE_INTERFACE, 202 std::move(pipe.handle1), internal::MultiplexRouter::SINGLE_INTERFACE,
226 false, base::ThreadTaskRunnerHandle::Get())); 203 false, base::ThreadTaskRunnerHandle::Get()));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 240 }
264 241
265 uint32_t counter() const { return counter_; } 242 uint32_t counter() const { return counter_; }
266 243
267 void Reset() { counter_ = 0; } 244 void Reset() { counter_ = 0; }
268 245
269 private: 246 private:
270 uint32_t counter_ = 0; 247 uint32_t counter_ = 0;
271 }; 248 };
272 249
273 TEST_F(MojoBindingsPerftest, RouterDispatchCost) {
274 MessagePipe pipe;
275 internal::Router router(std::move(pipe.handle0), FilterChain(), false,
276 base::ThreadTaskRunnerHandle::Get(), 0u);
277 CounterReceiver receiver;
278 router.set_incoming_receiver(&receiver);
279
280 static const uint32_t kIterations[] = {1000, 3000000};
281
282 for (size_t i = 0; i < 2; ++i) {
283 receiver.Reset();
284 base::TimeTicks start_time = base::TimeTicks::Now();
285 for (size_t j = 0; j < kIterations[i]; ++j) {
286 internal::MessageBuilder builder(0, 8);
287 bool result =
288 router.SimulateReceivingMessageForTesting(builder.message());
289 DCHECK(result);
290 }
291
292 base::TimeTicks end_time = base::TimeTicks::Now();
293 base::TimeDelta duration = end_time - start_time;
294 CHECK_EQ(kIterations[i], receiver.counter());
295
296 if (i == 1) {
297 test::LogPerfResult("RouterDispatchCost", nullptr,
298 kIterations[i] / duration.InSecondsF(),
299 "times/second");
300 }
301 }
302 }
303
304 TEST_F(MojoBindingsPerftest, MultiplexRouterDispatchCost) { 250 TEST_F(MojoBindingsPerftest, MultiplexRouterDispatchCost) {
305 MessagePipe pipe; 251 MessagePipe pipe;
306 scoped_refptr<internal::MultiplexRouter> router(new internal::MultiplexRouter( 252 scoped_refptr<internal::MultiplexRouter> router(new internal::MultiplexRouter(
307 std::move(pipe.handle0), internal::MultiplexRouter::SINGLE_INTERFACE, 253 std::move(pipe.handle0), internal::MultiplexRouter::SINGLE_INTERFACE,
308 true, base::ThreadTaskRunnerHandle::Get())); 254 true, base::ThreadTaskRunnerHandle::Get()));
309 CounterReceiver receiver; 255 CounterReceiver receiver;
310 InterfaceEndpointClient client( 256 InterfaceEndpointClient client(
311 router->CreateLocalEndpointHandle(kMasterInterfaceId), &receiver, nullptr, 257 router->CreateLocalEndpointHandle(kMasterInterfaceId), &receiver, nullptr,
312 false, base::ThreadTaskRunnerHandle::Get(), 0u); 258 false, base::ThreadTaskRunnerHandle::Get(), 0u);
313 259
(...skipping 16 matching lines...) Expand all
330 if (i == 1) { 276 if (i == 1) {
331 test::LogPerfResult("MultiplexRouterDispatchCost", nullptr, 277 test::LogPerfResult("MultiplexRouterDispatchCost", nullptr,
332 kIterations[i] / duration.InSecondsF(), 278 kIterations[i] / duration.InSecondsF(),
333 "times/second"); 279 "times/second");
334 } 280 }
335 } 281 }
336 } 282 }
337 283
338 } // namespace 284 } // namespace
339 } // namespace mojo 285 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/BUILD.gn ('k') | mojo/public/cpp/bindings/tests/router_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698