Skip to content

Commit

Permalink
[nfc] kj::HttpHeaders parse simple benchmark (#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea authored Aug 24, 2023
1 parent 9929604 commit 8533248
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/workerd/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand All @@ -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",
],
)

Expand All @@ -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",
],
)
46 changes: 46 additions & 0 deletions src/workerd/tests/bench-headers.c++
Original file line number Diff line number Diff line change
@@ -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 <workerd/tests/bench-tools.h>
#include <kj/compat/http.h>

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<kj::HttpHeaderTable> 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<kj::HttpHeaders::Request>());
}
}

} // namespace
} // namespace workerd

0 comments on commit 8533248

Please sign in to comment.