summaryrefslogtreecommitdiff
path: root/test/lib/bench.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 04:38:59 -0300
committerGabriel Schneider <[email protected]>2026-11-20 04:39:53 -0300
commit403b46922af6e4e2012cd15f5f3f5a5702eef7e7 (patch)
tree44e4df5fbc12e77210fbcafa50f29d23c93caa05 /test/lib/bench.zig
parenta3634ab3dbf2fabd997f137c47eafd7bc6c442b0 (diff)
downloadpardes-403b46922af6e4e2012cd15f5f3f5a5702eef7e7.tar.gz
pardes-403b46922af6e4e2012cd15f5f3f5a5702eef7e7.zip
test: test/lib becomes test/consumer, the package a consumer would write, in both of build.zig's head-comment shapes (pardes-build-2 item 5; the start design's step 3): `pardes-syntax` with `.grammars = .minimal` (lib.zig, as before), and `pardes-editor` with `.grammars = .none, .editor = true` and a grammar of its own, C's, built by this package from the very package pardes's manifest pins (`ts_c`, its own build's `tree-sitter-c` artifact, static, ReleaseFast) and linked into the editor's test and the bench, so the case sketchbook's examples/live is (pardes compiles no grammar for it; the program hands one in at run time) is gated here and not only in sketchbook; no network: `lib-test` runs it with `--pkg-dir ../../zig-pkg`, which has that package; the package is named `pardes_consumer` (a new fingerprint, as zig asks for a renamed package); lib-test's run step is named for what it is, so `--summary all` shows `zig build test in test/consumer, a package that depends on pardes success`, under `unit-test` as before; the package's own run: 29/29 steps, 11/11 tests (3 of the syntax, 8 of the editor), its bench builds and runs; build/tools.zig, build.zig's head comment, core/lib_syntax.zig, docs/next-editor.md, the manual and the changelog name test/consumer; the stale `test/lib/zig-pkg` (1.1 GB, untracked, from a run without --pkg-dir) deleted with the old directory. Scripts and notes outside the tree that name test/lib (its cache among them: a wipe of `test/lib/.zig-cache` now misses `test/consumer/.zig-cache`) are listed in the agent's report for the coordinator
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/lib/bench.zig')
-rw-r--r--test/lib/bench.zig80
1 files changed, 0 insertions, 80 deletions
diff --git a/test/lib/bench.zig b/test/lib/bench.zig
deleted file mode 100644
index 7e945064..00000000
--- a/test/lib/bench.zig
+++ /dev/null
@@ -1,80 +0,0 @@
-//! What a key costs on the library (`zig build bench -- <KiB> <keys>`, Debug
-//! or -Doptimize): a text of that size in the C grammar's shape, a key
-//! typed into its middle `keys` times, each with an arena of its own; the
-//! 4 KiB pages of the value a typed character changes; a full parse of the
-//! text. `keys` 0 makes the text alone, to count what the keys add; a
-//! third argument, `pages`, counts the pages (a copy and a compare a key,
-//! which an instruction count of the keys leaves out).
-const std = @import("std");
-const pe = @import("pardes-editor");
-
-const Ed = pe.Editor(.{ .text = 128 * 1024, .undo = 512 * 1024 });
-
-extern fn tree_sitter_c() *const pe.syntax.ts.Language;
-
-fn now() u64 {
- var ts: std.c.timespec = undefined;
- _ = std.c.clock_gettime(.MONOTONIC, &ts);
- return @as(u64, @intCast(ts.sec)) * std.time.ns_per_s + @as(u64, @intCast(ts.nsec));
-}
-
-pub fn main(init: std.process.Init) !void {
- const gpa = std.heap.page_allocator;
- const args = try init.minimal.args.toSlice(init.arena.allocator());
- const kib = try std.fmt.parseInt(usize, args[1], 10);
- const keys = try std.fmt.parseInt(usize, args[2], 10);
- const count_pages = args.len > 3;
- var text: std.ArrayList(u8) = .empty;
- var i: usize = 0;
- while (text.items.len < kib * 1024) : (i += 1) try text.print(gpa, "int f{d}(int x) {{ return x + {d}; }}\n", .{ i, i });
- text.items.len = kib * 1024;
- const ed = try gpa.create(Ed);
- ed.* = .{};
- try ed.load(text.items);
- var arena = std.heap.ArenaAllocator.init(gpa);
- defer arena.deinit();
- // to the middle, into insert mode
- for ([_]pe.Key{ .{ .cp = '%', .text = "%" }, .{ .cp = ';', .text = ";" } }) |k| _ = ed.key(arena.allocator(), null, k);
- var to_middle: [8]u8 = undefined;
- for (std.fmt.bufPrint(&to_middle, "{d}G", .{text.items.len / 2 / 32}) catch unreachable) |c| _ = ed.key(arena.allocator(), null, .{ .cp = c, .text = &.{c} });
- _ = ed.key(arena.allocator(), null, .{ .cp = 'i', .text = "i" });
- _ = arena.reset(.free_all);
- if (keys == 0) return;
-
- const before = try gpa.create(Ed);
- var pages_max: usize = 0;
- var pages_sum: usize = 0;
- var key_ns: u64 = 0;
- for (0..keys) |n| {
- if (count_pages) before.* = ed.*;
- const t0 = now();
- const out = ed.key(arena.allocator(), null, .{ .cp = 'a' + @as(u21, @intCast(n % 26)), .text = &.{'a' + @as(u8, @intCast(n % 26))} });
- key_ns += now() - t0;
- if (out != .done) return error.NotTyped;
- _ = arena.reset(.retain_capacity);
- if (!count_pages) continue;
- const a = std.mem.asBytes(before);
- const b = std.mem.asBytes(ed);
- var pages: usize = 0;
- var at: usize = 0;
- while (at < a.len) : (at += 4096) {
- const end = @min(at + 4096, a.len);
- if (!std.mem.eql(u8, a[at..end], b[at..end])) pages += 1;
- }
- pages_max = @max(pages_max, pages);
- pages_sum += pages;
- }
- const per_key = key_ns / keys;
-
- pe.syntax.start(std.heap.smp_allocator); // tree-sitter mallocs: not a page each
- const lang: pe.Language = .{ .name = "c-as-dsl", .ext = ".cdsl", .ts = tree_sitter_c() };
- var syn: pe.Syntax = .{};
- // the parser and its queries made once, then the parse alone timed
- _ = syn.parse(arena.allocator(), ed, lang) orelse return error.NoTree;
- syn.tree.?.destroy();
- syn.tree = null;
- const p0 = now();
- _ = syn.parse(arena.allocator(), ed, lang) orelse return error.NoTree;
- const parse = now() - p0;
- std.debug.print("{d} KiB: {d} keys, {d} ns a key, pages changed a key {d} max {d:.2} mean, value {d} bytes, full parse {d} ns\n", .{ kib, keys, per_key, pages_max, @as(f64, @floatFromInt(pages_sum)) / @as(f64, @floatFromInt(keys)), @sizeOf(Ed), parse });
-}