Skip to content

Commit 6a57754

Browse files
authored
Merge pull request #2 from floatdrop/add-http-iterator-to-benchmarks
feat(bench): add std.http.HeadParser to benchmarks
2 parents f8cc9b7 + 7902603 commit 6a57754

5 files changed

Lines changed: 133 additions & 8 deletions

File tree

bench/Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
bench-poop: build-picohttpparser build-httparse build-hparse
2-
poop -d 50000 "./picohttpparser/picohttpparser" "./bench-httparse/target/release/bench-httparse" "./hparse/zig-out/bin/hparse"
1+
bench-poop: build-picohttpparser build-httparse build-hparse build-headparser
2+
poop -d 50000 "./picohttpparser/picohttpparser" "./bench-httparse/target/release/bench-httparse" "./hparse/zig-out/bin/hparse" "./headparser/zig-out/bin/headparser"
33

44
bench-poop-log:
5-
poop -d 10000 "./picohttpparser/picohttpparser" "./bench-httparse/target/release/bench-httparse" "./hparse/zig-out/bin/hparse" > bench.txt
5+
poop -d 10000 "./picohttpparser/picohttpparser" "./bench-httparse/target/release/bench-httparse" "./hparse/zig-out/bin/hparse" "./headparser/zig-out/bin/headparser" > bench.txt
66

7-
bench-hyperfine: build-picohttpparser build-httparse build-hparse
8-
hyperfine "./hparse/zig-out/bin/hparse" "./picohttpparser/picohttpparser" "./bench-httparse/target/release/bench-httparse" --export-json bench.json
7+
bench-hyperfine: build-picohttpparser build-httparse build-hparse build-headparser
8+
hyperfine "./hparse/zig-out/bin/hparse" "./picohttpparser/picohttpparser" "./bench-httparse/target/release/bench-httparse" "./headparser/zig-out/bin/headparser" --export-json bench.json
99

1010
bench-poop-skylake: build-httparse-skylake build-hparse-skylake
1111
poop -d 10000 "./bench-httparse/target/release/bench-httparse" "./hparse/zig-out/bin/hparse"
@@ -22,11 +22,14 @@ build-httparse:
2222
build-hparse:
2323
cd hparse && zig build -Doptimize=ReleaseFast && cd ..
2424

25+
build-headparser:
26+
cd headparser && zig build -Doptimize=ReleaseFast && cd ..
27+
2528
build-httparse-skylake:
2629
cd bench-httparse && RUSTFLAGS=-Ctarget-feature=+avx2 cargo build --release && cd ..
2730

2831
build-hparse-skylake:
2932
cd hparse && zig build -Dcpu=skylake -Doptimize=ReleaseFast && cd ..
3033

3134
clean:
32-
rm picohttpparser/picohttpparser && rm -rf bench-httparse/target && rm -rf hparse/zig-out hparse/.zig-cache
35+
rm picohttpparser/picohttpparser && rm -rf bench-httparse/target && rm -rf hparse/zig-out hparse/.zig-cache && rm -rf headparser/zig-out headpaser/.zig-cache

bench/headparser/build.zig

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const std = @import("std");
2+
3+
// Although this function looks imperative, note that its job is to
4+
// declaratively construct a build graph that will be executed by an external
5+
// runner.
6+
pub fn build(b: *std.Build) void {
7+
// Standard target options allows the person running `zig build` to choose
8+
// what target to build for. Here we do not override the defaults, which
9+
// means any target is allowed, and the default is native. Other options
10+
// for restricting supported target set are available.
11+
const target = b.standardTargetOptions(.{});
12+
13+
// Standard optimization options allow the person running `zig build` to select
14+
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
15+
// set a preferred release mode, allowing the user to decide how to optimize.
16+
const optimize = b.standardOptimizeOption(.{});
17+
18+
// We will also create a module for our other entry point, 'main.zig'.
19+
const exe_mod = b.createModule(.{
20+
// `root_source_file` is the Zig "entry point" of the module. If a module
21+
// only contains e.g. external object files, you can make this `null`.
22+
// In this case the main source file is merely a path, however, in more
23+
// complicated build scripts, this could be a generated file.
24+
.root_source_file = b.path("src/main.zig"),
25+
.target = target,
26+
.optimize = optimize,
27+
});
28+
29+
// This creates another `std.Build.Step.Compile`, but this one builds an executable
30+
// rather than a static library.
31+
const exe = b.addExecutable(.{
32+
.name = "headparser",
33+
.root_module = exe_mod,
34+
});
35+
36+
// This declares intent for the executable to be installed into the
37+
// standard location when the user invokes the "install" step (the default
38+
// step when running `zig build`).
39+
b.installArtifact(exe);
40+
41+
// This *creates* a Run step in the build graph, to be executed when another
42+
// step is evaluated that depends on it. The next line below will establish
43+
// such a dependency.
44+
const run_cmd = b.addRunArtifact(exe);
45+
46+
// By making the run step depend on the install step, it will be run from the
47+
// installation directory rather than directly from within the cache directory.
48+
// This is not necessary, however, if the application depends on other installed
49+
// files, this ensures they will be present and in the expected location.
50+
run_cmd.step.dependOn(b.getInstallStep());
51+
52+
// This allows the user to pass arguments to the application in the build
53+
// command itself, like this: `zig build run -- arg1 arg2 etc`
54+
if (b.args) |args| {
55+
run_cmd.addArgs(args);
56+
}
57+
58+
// This creates a build step. It will be visible in the `zig build --help` menu,
59+
// and can be selected like this: `zig build run`
60+
// This will evaluate the `run` step rather than the default, which is "install".
61+
const run_step = b.step("run", "Run the app");
62+
run_step.dependOn(&run_cmd.step);
63+
64+
const exe_unit_tests = b.addTest(.{
65+
.root_module = exe_mod,
66+
});
67+
68+
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
69+
70+
// Similar to creating the run step earlier, this exposes a `test` step to
71+
// the `zig build --help` menu, providing a way for the user to request
72+
// running the unit tests.
73+
const test_step = b.step("test", "Run unit tests");
74+
test_step.dependOn(&run_exe_unit_tests.step);
75+
}

bench/headparser/build.zig.zon

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.{
2+
// This is the default name used by packages depending on this one. For
3+
// example, when a user runs `zig fetch --save <url>`, this field is used
4+
// as the key in the `dependencies` table. Although the user can choose a
5+
// different name, most users will stick with this provided value.
6+
//
7+
// It is redundant to include "zig" in this name because it is already
8+
// within the Zig package namespace.
9+
.name = .headparser_bench,
10+
11+
.fingerprint = 0x3894df1ca4908eec,
12+
13+
// This is a [Semantic Version](https://semver.org/).
14+
// In a future version of Zig it will be used for package deduplication.
15+
.version = "0.0.0",
16+
17+
// This field is optional.
18+
// This is currently advisory only; Zig does not yet do anything
19+
// with this value.
20+
//.minimum_zig_version = "0.11.0",
21+
22+
// This field is optional.
23+
// Each dependency must either provide a `url` and `hash`, or a `path`.
24+
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
25+
// Once all dependencies are fetched, `zig build` no longer requires
26+
// internet connectivity.
27+
.dependencies = .{},
28+
.paths = .{
29+
"build.zig",
30+
"build.zig.zon",
31+
"src",
32+
// For example...
33+
//"LICENSE",
34+
//"README.md",
35+
},
36+
}

bench/headparser/src/main.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const std = @import("std");
2+
const Head = std.http.Server.Request.Head;
3+
4+
pub fn main() !void {
5+
const buffer: []const u8 = "GET /cookies HTTP/1.1\r\nHost: 127.0.0.1:8090\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\nCookie: name=wookie\r\n\r\n";
6+
7+
var i: usize = 0;
8+
while (i < 1_000_000_0) : (i += 1) {
9+
_ = try Head.parse(buffer);
10+
}
11+
}

bench/hparse/build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
// internet connectivity.
2727
.dependencies = .{
2828
.hparse = .{
29-
.url = "https://github.com/nikneym/hparse/archive/0bbc197af29866d230c6f2d73454aef398d4d796.tar.gz",
30-
.hash = "1220fa7c037e154bb8880ffa686a0d26e71d1bad603eed09a3c70f534085557ada1d",
29+
.url = "https://github.com/nikneym/hparse/archive/f8cc9b77b57fe942c3319b597fb0aee4f131c47f.tar.gz",
30+
.hash = "hparse-0.2.0-IukW0s67AADCDZ7ROogFU5EJAVLyI8aiR0LPNvZd88OK",
3131
},
3232
},
3333
.paths = .{

0 commit comments

Comments
 (0)