summaryrefslogtreecommitdiff
path: root/test/perf.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/perf.zig')
-rw-r--r--test/perf.zig109
1 files changed, 108 insertions, 1 deletions
diff --git a/test/perf.zig b/test/perf.zig
index 17098f3d..8e622680 100644
--- a/test/perf.zig
+++ b/test/perf.zig
@@ -426,6 +426,8 @@ const Options = struct {
search: bool = false,
/// A picker's key and frame (`measurePick`).
pick: bool = false,
+ /// The walk UI's line F: registers, painted targets, themes (`measureWalkF`).
+ walkf: bool = false,
terminal_mib: ?usize = null,
/// The real binary's keystroke-to-present, `yes` stream and big open
/// (a tty pardes), or its keystrokes alone (a pardes-gui).
@@ -442,7 +444,7 @@ const Options = struct {
while (i < args.len) : (i += 1) {
const arg = args[i];
if (!std.mem.startsWith(u8, arg, "--")) return error.UnknownOption;
- const option = std.meta.stringToEnum(enum { json, creation, startup, mini, search, pick, @"terminal-mib", @"self-test", reps, cols, rows, base, only, op, @"max-ratio", live, @"live-gui" }, arg[2..]) orelse
+ const option = std.meta.stringToEnum(enum { json, creation, startup, mini, search, pick, walkf, @"terminal-mib", @"self-test", reps, cols, rows, base, only, op, @"max-ratio", live, @"live-gui" }, arg[2..]) orelse
return error.UnknownOption;
switch (option) {
.json => opts.json = true,
@@ -451,6 +453,7 @@ const Options = struct {
.mini => opts.mini = true,
.search => opts.search = true,
.pick => opts.pick = true,
+ .walkf => opts.walkf = true,
.@"self-test" => opts.self_test = true,
else => {
i += 1;
@@ -514,6 +517,7 @@ pub fn main(init: std.process.Init) !void {
if (opts.mini) return measureMini(init.io, init.gpa, reps, opts.json);
if (opts.search) return measureSearch(init.io);
if (opts.pick) return measurePick(init.io);
+ if (opts.walkf) return measureWalkF(init.io);
if (opts.live) |exe| return measureLive(init.io, exe, false, reps, opts.json);
if (opts.live_gui) |exe| return measureLive(init.io, exe, true, reps, opts.json);
// The image-frame cells load the image addon by the path the build baked
@@ -1920,6 +1924,38 @@ fn measureSearch(io: std.Io) !void {
}
slow.report("fill", pattern, set.hits.items.len);
}
+
+ // A key typed into a text prompt in the tag (core/Prompt.zig) on a 1 MB
+ // file, with its frame: `/` from the middle (its places from the view on,
+ // a frame's budget a tick after), `s` over the whole text (`%`).
+ const mb: Fixture = .{ .name = "onemeg", .lines = 17_000, .cols = 60 };
+ const mb_path = try std.fmt.allocPrint(gpa, "{s}/{s}.zig", .{ dir, mb.name });
+ defer gpa.free(mb_path);
+ const mb_text = try generate(mb);
+ try writeFile(mb_path, mb_text);
+ std.debug.print("prompt keys over {d} bytes\n", .{mb_text.len});
+ gpa.free(mb_text);
+ for ([_][]const u8{ "/", "%s" }) |opener| for ([_][]const u8{ "helper", "qqq" }) |typed| {
+ const core = try boot();
+ defer core.deinit();
+ pardes.look.lookAt(core, 0, mb_path);
+ pump(core);
+ const id = filePane(core) orelse return error.OpenDidNotOpenFile;
+ const pane = core.panes[id].?;
+ seek(pane, mb, 0);
+ pane.file.?.scroll = mb.lines / 2;
+ pane.body.cur_row = @intCast(mb.lines / 2);
+ _ = try frame(core);
+ for (opener) |c| core.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ _ = try frame(core);
+ for (typed, 0..) |c, n| {
+ const was = counter.read();
+ const t0 = nowNs();
+ core.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ _ = try frame(core);
+ std.debug.print("prompt {s} \"{s}\": {d} instructions, {d} us (key and frame)\n", .{ opener, typed[0 .. n + 1], counter.read() -| was, (nowNs() -| t0) / 1000 });
+ }
+ };
}
/// `--pick`: a picker's hot paths (core/Pick.zig, walk UI line D), each
@@ -1997,6 +2033,77 @@ fn measurePick(io: std.Io) !void {
if (!std.mem.endsWith(u8, landing.file.?.path, ".zig") or std.mem.indexOf(u8, landing.file.?.path, "pickme_") == null) return error.NoPreview;
}
+/// `--walkf`: line F's hot paths in a 2,000-line file, each a step and
+/// the frame that draws it, its instructions counted: a key in the
+/// registers' level unrolled (Down, its value step read again); a frame
+/// with `]`'s targets painted against one at rest; a cursor move in the
+/// themes picker (the window wearing the next theme).
+fn measureWalkF(io: std.Io) !void {
+ var random: [12]u8 = undefined;
+ io.random(&random);
+ const dir = try std.fmt.allocPrint(gpa, "/tmp/pardes-walkf-{x}", .{random});
+ defer gpa.free(dir);
+ try std.Io.Dir.createDirAbsolute(io, dir, .default_dir);
+ defer std.Io.Dir.cwd().deleteTree(io, dir) catch {};
+ const path = try std.fmt.allocPrint(gpa, "{s}/walkf.zig", .{dir});
+ defer gpa.free(path);
+ var body: std.ArrayList(u8) = .empty;
+ defer body.deinit(gpa);
+ for (0..250) |i| try body.print(gpa, "/// The {d}th.\nfn f{d}(a: u32) u32 {{\n const b = a + {d};\n return b;\n}}\n\ntest \"f{d}\" {{\n}}\n", .{ i, i, i, i });
+ try writeFile(path, body.items);
+ var counter: Instructions = try .open();
+ defer counter.close();
+ const core = try boot();
+ defer core.deinit();
+ core.settings.jumps = .walk;
+ pardes.look.lookAt(core, 0, path);
+ pump(core);
+ _ = filePane(core) orelse return error.OpenDidNotOpenFile;
+ for ("abcdefgh", 0..) |r, i| try core.registers.put(gpa, r, body.items[i * 40 ..][0..200], 0, 1, true);
+ try frame(core);
+ const Step = struct {
+ fn run(c: *pardes.Pardes, ev: pardes.Event, n: *Instructions, s: *Slowest) !void {
+ const was = n.read();
+ const t0 = nowNs();
+ c.update(ev);
+ try frame(c);
+ s.add(nowNs() -| t0, n.read() -| was, 0);
+ }
+ };
+ const shown = struct {
+ fn wait(c: *pardes.Pardes) !void {
+ c.advance(c.clock.now_ns);
+ c.clock.now_ns = c.view().tag_state.due_ns;
+ try frame(c);
+ }
+ };
+ // Registers: `"`, its level shown, unrolled; then Down over its rows.
+ core.update(.{ .key = .{ .cp = '"' } });
+ try shown.wait(core);
+ core.update(.{ .key = .{ .cp = pardes.Key.down } });
+ var regs: Slowest = .{};
+ for (0..8) |_| try Step.run(core, .{ .key = .{ .cp = pardes.Key.down } }, &counter, &regs);
+ regs.report("registers Down + frame", "\"", 0);
+ core.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ // A frame at rest, then frames with `]`'s targets painted.
+ var rest: Slowest = .{};
+ var painted: Slowest = .{};
+ for (0..8) |_| try Step.run(core, .tick, &counter, &rest);
+ core.update(.{ .key = .{ .cp = ']' } });
+ try shown.wait(core);
+ for (0..8) |_| try Step.run(core, .tick, &counter, &painted);
+ rest.report("tick + frame at rest", "", 0);
+ painted.report("tick + frame, ] painted", "]", 0);
+ core.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ // The themes picker: Down, the window wearing the next.
+ pardes.Pick.open(core, core.view().active, .themes, "", "", "");
+ try frame(core);
+ var themes: Slowest = .{};
+ for (0..8) |_| try Step.run(core, .{ .key = .{ .cp = pardes.Key.down } }, &counter, &themes);
+ themes.report("themes Down + frame", "", 0);
+ if (core.theme_preview == null) return error.NoThemePreview;
+}
+
/// The longest of a scan's calls.
const Slowest = struct {
calls: usize = 0,