From d37373a983f973d62368b68cea44a108b815d881 Mon Sep 17 00:00:00 2001 From: yhirose Date: Wed, 25 Jun 2025 16:46:49 -0400 Subject: [PATCH] Performance investigation --- test/test.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/test.cc b/test/test.cc index 08b786d..4797795 100644 --- a/test/test.cc +++ b/test/test.cc @@ -3368,14 +3368,16 @@ TEST_F(ServerTest, GetMethod200) { EXPECT_EQ("Hello World!", res->body); } -TEST(BenchmarkTest, SimpleGetPerformance) { +void performance_test(const char *host) { + auto port = 1234; + Server svr; svr.Get("/benchmark", [&](const Request & /*req*/, Response &res) { res.set_content("Benchmark Response", "text/plain"); }); - auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); }); + auto listen_thread = std::thread([&]() { svr.listen(host, port); }); auto se = detail::scope_exit([&] { svr.stop(); listen_thread.join(); @@ -3384,7 +3386,7 @@ TEST(BenchmarkTest, SimpleGetPerformance) { svr.wait_until_ready(); - Client cli("localhost", PORT); + Client cli(host, port); const int NUM_REQUESTS = 50; const int MAX_AVERAGE_MS = 5; @@ -3405,13 +3407,18 @@ TEST(BenchmarkTest, SimpleGetPerformance) { .count(); double avg_ms = static_cast(total_ms) / NUM_REQUESTS; - std::cout << "Standalone: " << NUM_REQUESTS << " requests in " << total_ms - << "ms (avg: " << avg_ms << "ms)" << std::endl; + std::cout << "Peformance test at \"" << host << "\": " << NUM_REQUESTS + << " requests in " << total_ms << "ms (avg: " << avg_ms << "ms)" + << std::endl; EXPECT_LE(avg_ms, MAX_AVERAGE_MS) - << "Standalone test too slow: " << avg_ms << "ms (Issue #1777)"; + << "Performance is too slow: " << avg_ms << "ms (Issue #1777)"; } +TEST(BenchmarkTest, localhost) { performance_test("localhost"); } + +TEST(BenchmarkTest, v6) { performance_test("::1"); } + TEST_F(ServerTest, GetEmptyFile) { auto res = cli_.Get("/empty_file"); ASSERT_TRUE(res);