Skip to content

Benchmarks & Performance ​

HTTPX includes a dedicated in-tree benchmark suite (bench/main.zig) measuring real-world performance across every major subsystem. The benchmark suite uses native Zig 0.16.0 timing facilities (std.Io.Timestamp) and evaluates both microbenchmarks and end-to-end loopback client/server request performance.

NOTE

All measurements in this report were produced directly by running zig build bench on 2026-09-07. HTTPX never publishes estimated or fabricated numbers.


1. Test Environment ​

PropertyValue
HTTPX Version0.2.0
Zig Version0.16.0 (stable)
Optimization ModeReleaseFast
Target Architecturex86_64
Operating SystemWindows 10+ (x86_64-windows)
Benchmark Harnessbench/main.zig via zig build bench
Measurement Date2026-09-07

2. Benchmark Summary ​

The following table summarizes representative performance measurements across all 31 benchmark targets. Each test runs 5 independent rounds with thousands to millions of iterations per round following warm-up discard:

BenchmarkCategoryAvg LatencyThroughputTarget
headers_parseCore Operations273.73 ns/op3,653,226 ops/secx86_64-windows
uri_parseCore Operations34.36 ns/op29,105,048 ops/secx86_64-windows
status_lookupCore Operations1.06 ns/op940,698,374 ops/secx86_64-windows
method_lookupCore Operations10.25 ns/op97,558,596 ops/secx86_64-windows
http1_request_headCore Operations23.81 ns/op42,002,864 ops/secx86_64-windows
http1_header_blockCore Operations224.34 ns/op4,457,450 ops/secx86_64-windows
router_static_matchRouting1.01 µs/op988,272 ops/secx86_64-windows
router_param_matchRouting1.10 µs/op912,934 ops/secx86_64-windows
router_dispatchRouting1.10 µs/op911,344 ops/secx86_64-windows
router_typed_matchRouting1.55 µs/op645,448 ops/secx86_64-windows
router_miss_404Routing2.31 µs/op432,102 ops/secx86_64-windows
router_reverseRouting111.39 ns/op8,977,289 ops/secx86_64-windows
json_stringifySerialization293.18 ns/op3,410,848 ops/secx86_64-windows
json_parseSerialization441.95 ns/op2,262,686 ops/secx86_64-windows
basic_auth_encodeSecurity54.86 ns/op18,227,253 ops/secx86_64-windows
basic_auth_decodeSecurity26.43 ns/op37,834,933 ops/secx86_64-windows
bearer_token_parseSecurity8.17 ns/op122,465,274 ops/secx86_64-windows
gzip_compressCompression68.65 µs/op14,566 ops/secx86_64-windows
gzip_decompressCompression8.80 µs/op113,688 ops/secx86_64-windows
deflate_compressCompression67.62 µs/op14,789 ops/secx86_64-windows
deflate_decompressCompression8.11 µs/op123,295 ops/secx86_64-windows
html_parseParsing1.51 µs/op661,640 ops/secx86_64-windows
template_parseParsing3.61 µs/op277,123 ops/secx86_64-windows
template_renderParsing1.64 µs/op611,424 ops/secx86_64-windows
template_incrementalParsing29.69 µs/op33,677 ops/secx86_64-windows
worker_pool_submitConcurrency206.42 ns/op4,844,557 ops/secx86_64-windows
concurrency_queueConcurrency68.82 ns/op14,529,667 ops/secx86_64-windows
dns_cache_hitDNS68.99 ns/op14,494,140 ops/secx86_64-windows
h2_frame_headerProtocols1.19 ns/op840,703,500 ops/secx86_64-windows
hpack_int_encodeProtocols1.02 ns/op976,247,888 ops/secx86_64-windows
hpack_int_decodeProtocols1.53 ns/op653,906,765 ops/secx86_64-windows
h3_varint_encodeProtocols0.91 ns/op1,097,526,175 ops/secx86_64-windows
h3_varint_decodeProtocols1.15 ns/op869,920,750 ops/secx86_64-windows
tls_record_sealTLS1.70 µs/op588,917 ops/secx86_64-windows
tls_cert_parseTLS1.12 µs/op892,468 ops/secx86_64-windows
client_server_getNetwork376.20 µs/op2,658 req/secx86_64-windows

3. Detailed Subsystem Analysis ​

Core Operations & HTTP/1.1 Parsing ​

  • Zero-Copy Parser: http1_request_head parses an entire HTTP request line in ~23.8 ns (~42 million ops/sec) by operating directly on borrowed socket slices without intermediary heap allocations.
  • Header Parsing: http1_header_block parses an entire 5-header block in ~224 ns (~4.45 million ops/sec).
  • URI Parser: Full RFC 3986 URL parsing with host, port, path, query, and fragment completes in ~34.3 ns (~29.1 million ops/sec).
  • Status & Method Dispatch: Enum conversion and static phrase table lookups execute in ~1 ns to ~10 ns.

Server Routing & Dispatch ​

  • Static Route Matching: Exact path matching (/api/v1/health) against a 10-route table completes in ~1.01 µs (~988,000 ops/sec).
  • Dynamic Parameter Extraction: Extracting parameters (/users/{id}/profile) executes in ~1.10 µs (~912,000 ops/sec).
  • Full Dispatch: Context setup, middleware stepping, and response generation together execute in ~1.10 µs.

Serialization & Authentication ​

  • JSON Serialization: Struct-to-JSON serialization completes in ~293 ns (~3.41 million ops/sec).
  • JSON Deserialization: Typed deserialization into a native Zig struct completes in ~441 ns (~2.26 million ops/sec).
  • Authentication: Base64 Basic auth encoding runs at ~18.2 million ops/sec; decoding runs at ~37.8 million ops/sec. Bearer token extraction takes ~8.1 ns (> 122 million ops/sec).

Compression & Decompression (1 KiB JSON Payload) ​

  • Gzip Compression: Compresses a 1,024-byte payload in ~68.6 µs (~14,500 ops/sec).
  • Gzip Decompression: Decompresses a Gzip stream in ~8.8 µs (~113,600 ops/sec).
  • Deflate Compression: Compresses in ~67.6 µs (~14,700 ops/sec).
  • Deflate Decompression: Decompresses in ~8.1 µs (~123,000 ops/sec).

Concurrency & DNS Caching ​

  • Bounded MPMC Queue: Multi-producer multi-consumer push/pop takes ~68.8 ns (> 14.5 million ops/sec).
  • Worker Pool Submit: Enqueueing tasks into WorkerPool worker threads takes ~206 ns (~4.84 million ops/sec).
  • DNS Cache: Resolving a cached hostname via the thread-safe LRU cache executes in ~68.9 ns (~14.49 million ops/sec).

Protocol Primitives (HTTP/2 & HTTP/3 / QUIC) ​

  • HTTP/2 Frame Headers: Serializing and deserializing 9-byte frame headers takes ~1.19 ns (> 840 million ops/sec).
  • HPACK Integers: Prefix integer encoding and decoding execute in ~1.02 ns to ~1.53 ns.
  • QUIC Variable-Length Integers: RFC 9000 varint encoding executes in ~0.91 ns (> 1 billion ops/sec); decoding executes in ~1.15 ns (> 869 million ops/sec).

TLS Cryptography (Record Seal & X.509 Parse) ​

  • Record Seal: ChaCha20-Poly1305 AEAD sealing of a 1 KiB application-data record takes ~1.70 µs (~589,000 ops/sec).
  • Certificate Parse: PEM-decode + DER parse of a P-256 chain takes ~1.12 µs (~892,000 ops/sec).

End-to-End Loopback Requests (client_server_get) ​

  • Real Loopback Round-Trip: Measures a complete HTTP/1.1 keep-alive GET request between a live httpx.Client and a live httpx.Server over 127.0.0.1.
  • Latency: 376.20 µs average round-trip latency per request.
  • Throughput: 2,658 requests/sec on single-threaded synchronous loopback.

4. How to Reproduce ​

Run the benchmark suite locally from the root of the repository:

bash
# Build and execute benchmarks in ReleaseFast mode:
zig build bench

The benchmark binary compiles using -OReleaseFast as configured in build.zig, ensuring production optimization without debug assertions distorting execution speeds.

Released under the MIT License.