diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 18:52:46 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:14 -0300 |
| commit | 3f4f26e0e40d06427e72f72e760d01adcdc0326c (patch) | |
| tree | d4bd56c6bc97f27e7ca11f3ee646513a9e4b116d /test/locations_bench.zig | |
| parent | 02ea4db25f9802e76112f3b4e69aa75e5a9464dc (diff) | |
| download | pardes-3f4f26e0e40d06427e72f72e760d01adcdc0326c.tar.gz pardes-3f4f26e0e40d06427e72f72e760d01adcdc0326c.zip | |
Reuse bounded source analysis and speed up result context traversal
Diffstat (limited to 'test/locations_bench.zig')
| -rw-r--r-- | test/locations_bench.zig | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/locations_bench.zig b/test/locations_bench.zig new file mode 100644 index 00000000..54cebb59 --- /dev/null +++ b/test/locations_bench.zig @@ -0,0 +1,61 @@ +const std = @import("std"); +const pds = @import("pardes"); +const loc = pds.locations_config; +fn now() u64 { + var ts: std.c.timespec = undefined; + _ = std.c.clock_gettime(.MONOTONIC, &ts); + return @as(u64, @intCast(ts.sec)) * 1_000_000_000 + @as(u64, @intCast(ts.nsec)); +} +// Run: zig build locations-bench -Doptimize=ReleaseFast +// Timed work is the real Output.fillResults pipeline. Fixtures are open unsaved +// sources; source generation, input duplication, rendering and subprocesses are +// excluded. Each layout/config starts with an empty source-analysis cache. +// Two repeats retain that cache and existing output. No latency threshold applies. +test "locations benchmark cold and warm formatting" { + if (!pds.syntax.supportsPath("large.zig")) return error.ZigGrammarRequired; + std.debug.print("layout,context,matches,source_bytes,phase,repeat,elapsed_ns\n", .{}); + const gpa = std.heap.smp_allocator; + for ([_]usize{ 100, 500, 1500 }) |functions| { + var source: std.Io.Writer.Allocating = .init(gpa); + defer source.deinit(); + var input: std.Io.Writer.Allocating = .init(gpa); + defer input.deinit(); + try source.writer.writeAll("pub const Module = struct {\n"); + var row: usize = 2; + for (0..functions) |i| { + try source.writer.print(" pub fn f{d}(x: u32) u32 {{\n", .{i}); + row += 1; + for (0..20) |j| { + try source.writer.print(" const v{d} = x + {d}; // explanatory source comment\n", .{ j, j }); + row += 1; + } + const line = " return x; // BENCH_MATCH"; + try source.writer.print("{s}\n }}\n", .{line}); + try input.writer.print("large.zig:{d}:1 {s}\n", .{ row, line }); + row += 2; + } + try source.writer.writeAll("};\n"); + const p = try pds.Pardes.init(gpa, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile(source.written()); + gpa.free(pane.file.?.path); + pane.file.?.path = try gpa.dupe(u8, "/bench/large.zig"); + for ([_]loc.Config.Layout{ .@"inline", .stacked }) |layout| { + for ([_]loc.Config{ .{ .context = 0, .tscontext = false }, .{ .context = 2, .tscontext = false }, .{ .context = 0, .tscontext = true }, .{ .context = 2, .tscontext = true } }, 0..) |config, mode| { + p.locations_config = config; + p.locations_cache.deinit(p.tree_sitter_gpa); + p.locations_cache = .{}; + p.locations_config.layout = layout; + for (0..3) |rep| { + _ = p.scratch.reset(.retain_capacity); + const data = try gpa.dupe(u8, input.written()); + const t = now(); + try pds.panes.Output.fillResults(p, 0, "/bench", .{ .cmd = .Grep }, "BENCH_MATCH", data, null); + const elapsed = now() - t; + const modes = [_][]const u8{ "off", "ordinary", "tree_sitter", "both" }; + std.debug.print("{s},{s},{d},{d},{s},{d},{d}\n", .{ @tagName(layout), modes[mode], functions, source.written().len, if (rep == 0) "cold" else "warm", rep, elapsed }); + } + } + } + } +} |
