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

Unified Diff: mojo/public/cpp/bindings/tests/bindings_perftest.cc

Issue 2314763003: Mojo C++ bindings: add perf tests to compare performance of Router/MultiplexRouter. (Closed)
Patch Set: . Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/tests/bindings_perftest.cc
diff --git a/mojo/public/cpp/bindings/tests/bindings_perftest.cc b/mojo/public/cpp/bindings/tests/bindings_perftest.cc
index db0dd05f062bc282237916bef1ee3dc1f5a45810..71f07eb54928ccf5911dec024a9fe2c87bf4eab8 100644
--- a/mojo/public/cpp/bindings/tests/bindings_perftest.cc
+++ b/mojo/public/cpp/bindings/tests/bindings_perftest.cc
@@ -9,6 +9,11 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/interface_endpoint_client.h"
+#include "mojo/public/cpp/bindings/lib/message_builder.h"
+#include "mojo/public/cpp/bindings/lib/multiplex_router.h"
+#include "mojo/public/cpp/bindings/lib/router.h"
+#include "mojo/public/cpp/bindings/message.h"
#include "mojo/public/cpp/test_support/test_support.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h"
@@ -133,5 +138,117 @@ TEST_F(MojoBindingsPerftest, InProcessPingPong) {
}
}
+class PingPongPaddle : public MessageReceiverWithResponderStatus {
+ public:
+ PingPongPaddle(MessageReceiver* sender) : sender_(sender) {}
+
+ void set_sender(MessageReceiver* sender) { sender_ = sender; }
+
+ bool Accept(Message* message) override {
+ uint32_t count = message->header()->name;
+ if (!quit_closure_.is_null()) {
+ count++;
+ if (count >= expected_count_) {
+ quit_closure_.Run();
+ return true;
+ }
+ }
+
+ internal::MessageBuilder builder(count, 8);
+ bool result = sender_->Accept(builder.message());
+ DCHECK(result);
+ return true;
+ }
+
+ bool AcceptWithResponder(Message* message,
+ MessageReceiverWithStatus* responder) override {
+ NOTREACHED();
+ return true;
+ }
+
+ void Serve(uint32_t expected_count) {
+ base::RunLoop run_loop;
+
+ expected_count_ = expected_count;
+ quit_closure_ = run_loop.QuitClosure();
+
+ internal::MessageBuilder builder(0, 8);
+ bool result = sender_->Accept(builder.message());
+ DCHECK(result);
+
+ run_loop.Run();
+ }
+
+ private:
+ uint32_t expected_count_ = 0;
+ MessageReceiver* sender_;
+ base::Closure quit_closure_;
+};
+
+TEST_F(MojoBindingsPerftest, RouterPingPong) {
+ MessagePipe pipe;
+ internal::Router router0(std::move(pipe.handle0), FilterChain(), false,
+ base::ThreadTaskRunnerHandle::Get(), 0u);
+ internal::Router router1(std::move(pipe.handle1), FilterChain(), false,
+ base::ThreadTaskRunnerHandle::Get(), 0u);
+ PingPongPaddle paddle0(&router0);
+ router0.set_incoming_receiver(&paddle0);
+ PingPongPaddle paddle1(&router1);
+ router1.set_incoming_receiver(&paddle1);
+
+ static const uint32_t kWarmUpIterations = 1000;
+ static const uint32_t kTestIterations = 100000;
+
+ paddle0.Serve(kWarmUpIterations);
+
+ const MojoTimeTicks start_time = MojoGetTimeTicksNow();
+ paddle0.Serve(kTestIterations);
+ const MojoTimeTicks end_time = MojoGetTimeTicksNow();
+
+ test::LogPerfResult(
+ "RouterPingPong", nullptr,
+ kTestIterations / MojoTicksToSeconds(end_time - start_time),
+ "pings/second");
+}
+
+TEST_F(MojoBindingsPerftest, MultiplexRouterPingPong) {
+ MessagePipe pipe;
+ scoped_refptr<internal::MultiplexRouter> router0(
+ new internal::MultiplexRouter(true, std::move(pipe.handle0),
+ base::ThreadTaskRunnerHandle::Get()));
+ scoped_refptr<internal::MultiplexRouter> router1(
+ new internal::MultiplexRouter(false, std::move(pipe.handle1),
+ base::ThreadTaskRunnerHandle::Get()));
+
+ PingPongPaddle paddle0(nullptr);
+ PingPongPaddle paddle1(nullptr);
+
+ InterfaceEndpointClient client0(
+ router0->CreateLocalEndpointHandle(kMasterInterfaceId), &paddle0,
+ base::MakeUnique<PassThroughFilter>(), false,
+ base::ThreadTaskRunnerHandle::Get(), 0u);
+ InterfaceEndpointClient client1(
+ router1->CreateLocalEndpointHandle(kMasterInterfaceId), &paddle1,
+ base::MakeUnique<PassThroughFilter>(), false,
+ base::ThreadTaskRunnerHandle::Get(), 0u);
+
+ paddle0.set_sender(&client0);
+ paddle1.set_sender(&client1);
+
+ static const uint32_t kWarmUpIterations = 1000;
+ static const uint32_t kTestIterations = 100000;
+
+ paddle0.Serve(kWarmUpIterations);
+
+ const MojoTimeTicks start_time = MojoGetTimeTicksNow();
+ paddle0.Serve(kTestIterations);
+ const MojoTimeTicks end_time = MojoGetTimeTicksNow();
+
+ test::LogPerfResult(
+ "MultiplexRouterPingPong", nullptr,
+ kTestIterations / MojoTicksToSeconds(end_time - start_time),
+ "pings/second");
+}
+
} // namespace
} // namespace mojo
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698