@@ -3155,6 +3155,47 @@ TEST_F(ServerTest, GetMethod200) {
31553155 EXPECT_EQ (" Hello World!" , res->body );
31563156}
31573157
3158+ TEST (BenchmarkTest, SimpleGetPerformance) {
3159+ Server svr;
3160+
3161+ svr.Get (" /benchmark" , [&](const Request & /* req*/ , Response &res) {
3162+ res.set_content (" Benchmark Response" , " text/plain" );
3163+ });
3164+
3165+ auto listen_thread = std::thread ([&svr]() { svr.listen (" localhost" , PORT); });
3166+ auto se = detail::scope_exit ([&] {
3167+ svr.stop ();
3168+ listen_thread.join ();
3169+ ASSERT_FALSE (svr.is_running ());
3170+ });
3171+
3172+ svr.wait_until_ready ();
3173+
3174+ Client cli (" localhost" , PORT);
3175+
3176+ const int NUM_REQUESTS = 50 ;
3177+ const int MAX_AVERAGE_MS = 5 ;
3178+
3179+ auto warmup = cli.Get (" /benchmark" );
3180+ ASSERT_TRUE (warmup);
3181+
3182+ auto start = std::chrono::high_resolution_clock::now ();
3183+ for (int i = 0 ; i < NUM_REQUESTS; ++i) {
3184+ auto res = cli.Get (" /benchmark" );
3185+ ASSERT_TRUE (res) << " Request " << i << " failed" ;
3186+ EXPECT_EQ (StatusCode::OK_200, res->status );
3187+ }
3188+ auto end = std::chrono::high_resolution_clock::now ();
3189+
3190+ auto total_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count ();
3191+ double avg_ms = static_cast <double >(total_ms) / NUM_REQUESTS;
3192+
3193+ std::cout << " Standalone: " << NUM_REQUESTS << " requests in " << total_ms
3194+ << " ms (avg: " << avg_ms << " ms)" << std::endl;
3195+
3196+ EXPECT_LE (avg_ms, MAX_AVERAGE_MS) << " Standalone test too slow: " << avg_ms << " ms (Issue #1777)" ;
3197+ }
3198+
31583199TEST_F (ServerTest, GetEmptyFile) {
31593200 auto res = cli_.Get (" /empty_file" );
31603201 ASSERT_TRUE (res);
0 commit comments