aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/http/io/benchmark/main.cpp
diff options
context:
space:
mode:
authorAlexSm <alex@ydb.tech>2024-01-09 18:56:40 +0100
committerGitHub <noreply@github.com>2024-01-09 18:56:40 +0100
commite95f266d2a3e48e62015220588a4fd73d5d5a5cb (patch)
treea8a784b6931fe52ad5f511cfef85af14e5f63991 /library/cpp/http/io/benchmark/main.cpp
parent50a65e3b48a82d5b51f272664da389f2e0b0c99a (diff)
downloadydb-e95f266d2a3e48e62015220588a4fd73d5d5a5cb.tar.gz
Library import 6 (#888)
Diffstat (limited to 'library/cpp/http/io/benchmark/main.cpp')
-rw-r--r--library/cpp/http/io/benchmark/main.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/library/cpp/http/io/benchmark/main.cpp b/library/cpp/http/io/benchmark/main.cpp
new file mode 100644
index 0000000000..2a3a07b3bb
--- /dev/null
+++ b/library/cpp/http/io/benchmark/main.cpp
@@ -0,0 +1,81 @@
+#include <library/cpp/http/io/headers.h>
+
+#include <benchmark/benchmark.h>
+
+#include <util/stream/str.h>
+
+void FindHeaderFirstMatch(benchmark::State& state) {
+ THttpHeaders headers;
+ headers.AddHeader("Host", "example.com");
+ Y_ENSURE(headers.FindHeader("Host"));
+ for (auto _ : state) {
+ auto header = headers.FindHeader("Host");
+ benchmark::DoNotOptimize(header);
+ }
+}
+
+void FindHeaderNoMatchSameSize(benchmark::State& state) {
+ THttpHeaders headers;
+ for (char c = 'a'; c <= 'z'; ++c) {
+ headers.AddHeader(TString::Join(c, "aaa"), "some value");
+ }
+ Y_ENSURE(!headers.FindHeader("Host"));
+ for (auto _ : state) {
+ auto header = headers.FindHeader("Host");
+ benchmark::DoNotOptimize(header);
+ }
+}
+
+void FindHeaderNoMatchDifferentSizesNoCommonPrefix(benchmark::State& state) {
+ THttpHeaders headers;
+ for (char c = 'a'; c <= 'z'; ++c) { // same number of headers as above
+ headers.AddHeader("aaaaa", "some value");
+ }
+ Y_ENSURE(!headers.FindHeader("Host"));
+ for (auto _ : state) {
+ auto header = headers.FindHeader("Host");
+ benchmark::DoNotOptimize(header);
+ }
+}
+
+void FindHeaderNoMatchDifferentSizesCommonPrefix(benchmark::State& state) {
+ THttpHeaders headers;
+ for (char c = 'a'; c <= 'z'; ++c) {
+ headers.AddHeader("Host2", "some value");
+ }
+ Y_ENSURE(!headers.FindHeader("Host"));
+ for (auto _ : state) {
+ auto header = headers.FindHeader("Host");
+ benchmark::DoNotOptimize(header);
+ }
+}
+
+void FindHeaderMoreRealisticUseCase(benchmark::State& state) {
+ TString requestHeaders(R"(Host: yandex.ru
+User-Agent: Mozilla/5.0 ...
+Accept: */*
+Accept-Language: en-US,en;q=0.5
+Accept-Encoding: gzip, deflate, br
+Content-Type: text/plain;charset=UTF-8
+Content-Length: 1234
+Origin: https://a.yandex-team.ru
+Connection: keep-alive
+Referer: https://a.yandex-team.ru/
+Sec-Fetch-Dest: empty
+Sec-Fetch-Mode: no-cors
+Sec-Fetch-Site: cross-site
+TE: trailers)");
+ TStringInput stream(requestHeaders);
+ THttpHeaders headers(&stream);
+ Y_ENSURE(headers.FindHeader("Content-Type"));
+ for (auto _ : state) {
+ auto header = headers.FindHeader("Content-Type");
+ benchmark::DoNotOptimize(header);
+ }
+}
+
+BENCHMARK(FindHeaderFirstMatch);
+BENCHMARK(FindHeaderNoMatchSameSize);
+BENCHMARK(FindHeaderNoMatchDifferentSizesNoCommonPrefix);
+BENCHMARK(FindHeaderNoMatchDifferentSizesCommonPrefix);
+BENCHMARK(FindHeaderMoreRealisticUseCase);