1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 });
}
}
}
}
}
|