diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/perf.zig | 105 |
1 files changed, 101 insertions, 4 deletions
diff --git a/test/perf.zig b/test/perf.zig index f36d64ac..ceef0de4 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -70,6 +70,31 @@ const Op = enum { /// the window: a kind's frame costs its window's cells, never its /// picture (docs: architecture ยง16.1, its trigger 5% of a frame). image_frame, + /// The walk UI's tag states (TagState.zig), each key pumped and the + /// frame that draws it: SPC struck at rest, its level shown when its + /// delay is up, Esc back to rest (three frames, two keys). + spc, + /// A Down in SPC's unrolled level: its cursor a row on, the band drawn. + spc_down, + /// A character typed in Help's field and a Backspace: its rows + /// filtered again each time (two keys). + help_type, + /// describe-key's `g d` replayed: the level and the leaf's doc under the + /// tag (two keys). + describe, + /// `j` and `k` at rest in the same loop (two keys, two frames): what + /// the tag states' keys compare with (key-down's frames each draw + /// another place of the file). + rest_keys, + + /// Run only when named (`--op`): a full run, its cells and the sums a + /// gate takes over them (perfops' "terminal on all") are as before. + fn named(o: Op) bool { + return switch (o) { + .spc, .spc_down, .help_type, .describe, .rest_keys => true, + else => false, + }; + } fn label(o: Op) []const u8 { return switch (o) { @@ -88,6 +113,11 @@ const Op = enum { .body_appends => "body-appends", .deep_selection => "deep-sel", .image_frame => "image-frame", + .spc => "spc", + .spc_down => "spc-down", + .help_type => "help-type", + .describe => "describe", + .rest_keys => "rest-keys", }; } }; @@ -524,6 +554,7 @@ pub fn main(init: std.process.Init) !void { for (fixtures, 0..) |fx, fi| { if (only) |name| if (!std.mem.eql(u8, name, fx.name)) continue; if (opts.op) |o| if (o != op) continue; + if (op.named() and opts.op == null) continue; cells[oi][fi] = try measure(op, fx, paths[fi], bytes[fi], reps); } } @@ -538,7 +569,7 @@ pub fn main(init: std.process.Init) !void { } } - if (opts.json) try reportJson(init.io, &cells, &term_cells, &bytes, opts) else reportText(&cells, &term_cells, &bytes, reps, opts.base, base); + if (opts.json) try reportJson(init.io, &cells, &term_cells, &bytes, opts) else reportText(&cells, &term_cells, &bytes, reps, opts.op, opts.base, base); if (opts.max_ratio) |ratio| try gate(&cells, &base.?, ratio); } @@ -583,6 +614,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u switch (op) { .image_frame => return measureImage(std.fs.path.dirname(path).?, samples, warmup), .client_key_down, .client_edit_char, .client_delete_undo => return measureClient(op, path, reps), + .spc, .spc_down, .help_type, .describe, .rest_keys => return measureTag(op, path, reps), else => {}, } if (op == .open) { @@ -637,7 +669,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u const wheel_row = rect.y + pardes.BOX_H; const t0 = nowNs(); switch (op) { - .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo => unreachable, + .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys => unreachable, .render, .deep_selection => {}, .key_down => core.update(.{ .key = .{ .cp = 'j', .text = "j" } }), .key_right => core.update(.{ .key = .{ .cp = 'l', .text = "l" } }), @@ -651,7 +683,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u _ = try frame(core); const dt = nowNs() -| t0; switch (op) { - .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo => unreachable, + .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys => unreachable, .body_write => if (pane.file.?.content.len != before.len + 8 * body_chunk.len) return error.BodyWriteWasNotAppended, .body_appends => if (pane.file.?.content.len != before.len + append_count * append_chunk_len) return error.BodyAppendsWereNotAppended, .render, .deep_selection => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col or pane.file.?.content.len != before.len) @@ -736,6 +768,68 @@ fn clientKey(a: *pardes.replica.Authority, r: *pardes.replica.Replica, ev: parde r.settle(); } +/// A tag state's keys on the fixture's pane, each pumped and its frame +/// drawn, from the state the op starts in (entered untimed); the state +/// checked after each repetition. +fn measureTag(op: Op, path: []const u8, reps: usize) !Cell { + const Key = pardes.Key; + const warmup = 3; + const samples = try gpa.alloc(u64, reps); + defer gpa.free(samples); + const core = try boot(); + defer core.deinit(); + pardes.look.lookAt(core, 0, path); + pump(core); + const id = filePane(core) orelse return error.OpenDidNotOpenFile; + core.view().active = id; + const enter: []const Key = switch (op) { + .spc, .rest_keys => &.{}, + .spc_down => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = Key.down } }, + .help_type => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = '?', .text = "?" } }, + .describe => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = 'h', .text = "h" }, .{ .cp = 'k', .text = "k" } }, + else => unreachable, + }; + for (enter) |k| core.update(.{ .key = k }); + pump(core); + _ = try frame(core); + const keys: []const Key = switch (op) { + .spc => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = Key.escape } }, + .spc_down => &.{.{ .cp = Key.down }}, + .help_type => &.{ .{ .cp = 'e', .text = "e" }, .{ .cp = Key.backspace } }, + .describe => &.{ .{ .cp = 'g', .text = "g" }, .{ .cp = 'd', .text = "d" } }, + .rest_keys => &.{ .{ .cp = 'j', .text = "j" }, .{ .cp = 'k', .text = "k" } }, + else => unreachable, + }; + const s = &core.view().tag_state; + for (0..warmup + samples.len) |n| { + const t0 = nowNs(); + for (keys) |k| { + core.update(.{ .key = k }); + pump(core); + _ = try frame(core); + // SPC's level when its delay is up: the frame that shows it. + if (op == .spc and k.cp == ' ') { + core.advance(core.clock.now_ns); + core.clock.now_ns = s.due_ns; + if (!pardes.TagState.shown(core, core.view())) return error.LevelNotShown; + _ = try frame(core); + } + } + const dt = nowNs() -| t0; + const held = switch (op) { + .spc => s.kind == .rest and s.root == null, + .spc_down => s.unrolled and core.panes[id].?.band_rows > 0, + .help_type => s.kind == .help and s.field.len == 0 and s.nhits > 0, + .describe => s.kind == .describe and s.found, + .rest_keys => s.kind == .rest and s.root == null and core.panes[id].?.body.cur_row == 0, + else => unreachable, + }; + if (!held) return error.TagStateLost; + if (n >= warmup) samples[n - warmup] = dt / 1000; + } + return summarize(samples); +} + fn measureImage(dir: []const u8, samples: []u64, warmup: usize) !Cell { const path = try std.fmt.allocPrint(gpa, "{s}/picture.ppm", .{dir}); defer gpa.free(path); @@ -1988,6 +2082,7 @@ fn reportText( term_cells: *const [std.enums.values(TermOp).len][term_fixtures.len]Cell, bytes: *const [fixtures.len]usize, reps: usize, + named: ?Op, base_path: ?[]const u8, base: ?Base, ) void { @@ -2011,6 +2106,7 @@ fn reportText( o("\n{s}\n", .{if (base != null) &@as([12 + fixtures.len * 20]u8, @splat('-')) else &@as([12 + fixtures.len * 13]u8, @splat('-'))}); var worst_jitter: f64 = 0; for (std.enums.values(Op), 0..) |op, oi| { + if (op.named() and named != op) continue; o("{s:<12}", .{op.label()}); for (0..fixtures.len) |fi| { const c = cells[oi][fi]; @@ -2100,6 +2196,7 @@ fn writeJson( for (fixtures, 0..) |fx, fi| { if (opts.only) |name| if (!std.mem.eql(u8, name, fx.name)) continue; if (opts.op) |o| if (o != op) continue; + if (op.named() and opts.op == null) continue; const c = cells[oi][fi]; try out.print("{s}{{\"op\":\"{s}\",\"fixture\":\"{s}\",\"min_us\":{d},\"med_us\":{d},\"p90_us\":{d},\"max_us\":{d}}}", .{ if (first) "" else ",", op.label(), fx.name, c.min_us, c.med_us, c.p90_us, c.max_us, @@ -2204,7 +2301,7 @@ fn parseBase(src: []const u8, opts: Options, bytes: *const [fixtures.len]usize) } for (fixtures, 0..) |fixture, fi| { if (opts.only) |name| if (!std.mem.eql(u8, name, fixture.name)) continue; - for (file_seen) |row| if (!row[fi]) return error.BaselineCoverage; + for (file_seen, std.enums.values(Op)) |row, op| if (!row[fi] and !op.named()) return error.BaselineCoverage; } if (opts.only == null) for (term_seen) |row| { for (row) |seen| if (!seen) return error.BaselineCoverage; |
