From b169e094b350ea13ca778360e1dd78c3215ef3e2 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Mon, 21 Sep 2020 15:38:29 +0800 Subject: [PATCH] add benchmark test. --- examples/client/main.cpp | 22 ++++++++++++++++++++++ examples/server/main.cpp | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 4cc54b7..68121af 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -600,7 +600,29 @@ void test_ssl() { std::getchar(); } +void benchmark_test(){ + rpc_client client; + bool r = client.connect("127.0.0.1", 9000); + if (!r) { + return; + } + + for (size_t i = 0; i < 1000000; i++) { + client.async_call("echo", [i](boost::system::error_code ec, string_view data) { + if (ec) { + return; + } + + }, "hello wolrd"); + std::this_thread::sleep_for(std::chrono::microseconds(2)); + } + + std::getchar(); + std::cout<<"benchmark test finished\n"; +} + int main() { +// benchmark_test(); test_sub1(); test_connect(); test_callback(); diff --git a/examples/server/main.cpp b/examples/server/main.cpp index c815e70..4f7c7f7 100644 --- a/examples/server/main.cpp +++ b/examples/server/main.cpp @@ -84,6 +84,7 @@ void async_echo(rpc_conn conn, const std::string& src) { } std::string echo(rpc_conn conn, const std::string& src) { + g_qps.increase(); return src; } @@ -98,7 +99,14 @@ void test_ssl() { server.run(); } +void benchmark_test(){ + rpc_server server(9000, std::thread::hardware_concurrency()); + server.register_handler("echo", echo); + server.run(); +} + int main() { +// benchmark_test(); rpc_server server(9000, std::thread::hardware_concurrency()); dummy d;