1
0
mirror of synced 2025-07-17 17:40:57 +03:00
* Fix #1601

* clang-format

* Fix Windows problem

* Use GetAddrInfoEx on Windows

* Fix Windows problem

* Add getaddrinfo_a

* clang-format

* Adjust Benchmark Test

* Test

* Fix Bench test

* Fix build error

* Fix build error

* Fix Makefile

* Fix build error

* Fix buid error
This commit is contained in:
yhirose
2025-06-29 00:13:09 -04:00
committed by GitHub
parent e6ff3d7ac2
commit ea850cbfa7
4 changed files with 357 additions and 32 deletions

View File

@ -3388,31 +3388,20 @@ void performance_test(const char *host) {
Client cli(host, port);
const int NUM_REQUESTS = 50;
const int MAX_AVERAGE_MS = 5;
auto warmup = cli.Get("/benchmark");
ASSERT_TRUE(warmup);
auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < NUM_REQUESTS; ++i) {
auto res = cli.Get("/benchmark");
ASSERT_TRUE(res) << "Request " << i << " failed";
EXPECT_EQ(StatusCode::OK_200, res->status);
}
auto res = cli.Get("/benchmark");
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status);
auto end = std::chrono::high_resolution_clock::now();
auto total_ms =
auto elapsed =
std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
.count();
double avg_ms = static_cast<double>(total_ms) / NUM_REQUESTS;
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)
<< "Performance is too slow: " << avg_ms << "ms (Issue #1777)";
EXPECT_LE(elapsed, 5) << "Performance is too slow: " << elapsed
<< "ms (Issue #1777)";
}
TEST(BenchmarkTest, localhost) { performance_test("localhost"); }