From fe62677a935e9a4d278b2640db38927909474d7f Mon Sep 17 00:00:00 2001 From: Ankit Patial Date: Sun, 18 Jan 2026 00:51:31 +0530 Subject: [PATCH] Rename test-bench to bench-2, update README with benchmark docs --- README.md | 41 ++++++++++++++++--- build.zig | 4 +- .../{comparison.zig => benchmark_2.zig} | 0 3 files changed, 37 insertions(+), 8 deletions(-) rename src/benchmarks/{comparison.zig => benchmark_2.zig} (100%) diff --git a/README.md b/README.md index 2af7e5b..cdad0c5 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,21 @@ const html = try engine.renderTpl(allocator, }); ``` +## Development + +### Run Tests + +```bash +zig build test +``` + +### Run Benchmarks + +```bash +zig build bench # Run rendering benchmarks +zig build bench-2 # Run comparison benchmarks +``` + ## Template Syntax ```pug @@ -91,15 +106,29 @@ html ## Benchmarks -2000 iterations on MacBook Air M2: +### Rendering Benchmarks (`zig build bench`) + +20,000 iterations on MacBook Air M2: + +| Template | Avg | Renders/sec | Output | +|----------|-----|-------------|--------| +| Simple | 11.81 us | 84,701 | 155 bytes | +| Medium | 21.10 us | 47,404 | 1,211 bytes | +| Complex | 33.48 us | 29,872 | 4,852 bytes | + +### Comparison Benchmarks (`zig build bench-2`) + +2,000 iterations vs Pug.js: | Template | Pugz | Pug.js | Speedup | |----------|------|--------|---------| -| simple-0 | 0.6ms | 2ms | 3.4x | -| simple-1 | 6.9ms | 9ms | 1.3x | -| simple-2 | 7.7ms | 9ms | 1.2x | -| if-expression | 6.0ms | 12ms | 2.0x | -| projects-escaped | 9.3ms | 86ms | 9.2x | +| simple-0 | 0.5ms | 2ms | 3.8x | +| simple-1 | 6.7ms | 9ms | 1.3x | +| simple-2 | 5.4ms | 9ms | 1.7x | +| if-expression | 4.4ms | 12ms | 2.7x | +| projects-escaped | 7.3ms | 86ms | 11.7x | +| search-results | 70.6ms | 41ms | 0.6x | +| friends | 682.1ms | 110ms | 0.2x | ## License diff --git a/build.zig b/build.zig index 5d2ed34..ac92f19 100644 --- a/build.zig +++ b/build.zig @@ -136,7 +136,7 @@ pub fn build(b: *std.Build) void { // ───────────────────────────────────────────────────────────────────────── const bench_tests = b.addTest(.{ .root_module = b.createModule(.{ - .root_source_file = b.path("src/benchmarks/comparison.zig"), + .root_source_file = b.path("src/benchmarks/benchmark_2.zig"), .target = target, .optimize = .ReleaseFast, .imports = &.{ @@ -148,7 +148,7 @@ pub fn build(b: *std.Build) void { const run_bench_tests = b.addRunArtifact(bench_tests); - const bench_test_step = b.step("test-bench", "Run comparison benchmarks (template-engine-bench)"); + const bench_test_step = b.step("bench-2", "Run comparison benchmarks (template-engine-bench)"); bench_test_step.dependOn(&run_bench_tests.step); // ───────────────────────────────────────────────────────────────────────── diff --git a/src/benchmarks/comparison.zig b/src/benchmarks/benchmark_2.zig similarity index 100% rename from src/benchmarks/comparison.zig rename to src/benchmarks/benchmark_2.zig