diff --git a/src/workerd/tests/BUILD.bazel b/src/workerd/tests/BUILD.bazel index b48d4f32996..b1bef7f25fe 100644 --- a/src/workerd/tests/BUILD.bazel +++ b/src/workerd/tests/BUILD.bazel @@ -8,7 +8,7 @@ wd_cc_library( visibility = ["//visibility:public"], deps = [ "@capnp-cpp//src/kj:kj-test", - "@com_google_benchmark//:benchmark", + "@com_google_benchmark//:benchmark", ], ) @@ -34,8 +34,8 @@ wd_cc_benchmark( name = "bench-json", srcs = ["bench-json.c++"], deps = [ - "@capnp-cpp//src/kj", "//src/workerd/api:r2-api_capnp", + "@capnp-cpp//src/kj", ], ) @@ -46,3 +46,11 @@ wd_cc_benchmark( "//src/workerd/util", ], ) + +wd_cc_benchmark( + name = "bench-headers", + srcs = ["bench-headers.c++"], + deps = [ + "@capnp-cpp//src/kj/compat:kj-http", + ], +) diff --git a/src/workerd/tests/bench-headers.c++ b/src/workerd/tests/bench-headers.c++ new file mode 100644 index 00000000000..c617f1e4fd4 --- /dev/null +++ b/src/workerd/tests/bench-headers.c++ @@ -0,0 +1,46 @@ +// Copyright (c) 2023 Cloudflare, Inc. +// Licensed under the Apache 2.0 license found in the LICENSE file or at: +// https://opensource.org/licenses/Apache-2.0 + +#include +#include + +namespace workerd { +namespace { + +struct Fixture: public benchmark::Fixture { + virtual ~Fixture() noexcept(true) {} + + void SetUp(benchmark::State& state) noexcept(true) override { + kj::HttpHeaderTable::Builder builder; + builder.add("Host"); + builder.add("Accept"); + builder.add("Content-Type"); + builder.add("Last-Modified"); + table = builder.build(); + } + + kj::Own table; +}; + +BENCHMARK_F(Fixture, Parse)(benchmark::State& state) { + for (auto _ : state) { + kj::HttpHeaders headers(*table); + + auto in = kj::heapString( + "GET /favicon.ico HTTP/1.1\r\n" + "Host: 0.0.0.0=5000\r\n" + "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" + "Accept-Language: en-us,en;q=0.5\r\n" + "Accept-Encoding: gzip,deflate\r\n" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" + "Keep-Alive: 300\r\n" + "Connection: keep-alive\r\n" + "\r\n"); + KJ_EXPECT(headers.tryParseRequest(in.asArray()).is()); + } +} + +} // namespace +} // namespace workerd