summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/bench_main.zig42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/bench_main.zig b/tools/bench_main.zig
index b3470c2..fbaea8a 100644
--- a/tools/bench_main.zig
+++ b/tools/bench_main.zig
@@ -42,6 +42,13 @@ const Sweep = enum {
length,
/// One-off operations at a fixed geometry: motions, an insert, and a forced full repaint.
ops,
+ /// WHERE in a fixed line the edit happens. The length sweep shows cost rising with the line,
+ /// but a line's length and the cursor's column grow together while typing, so that experiment
+ /// cannot tell "the document is big" from "the cursor is far along it". This one holds the
+ /// document constant at one long line and moves only the column, which separates them: a cost
+ /// that follows the column is a walk from the start of the line (grapheme/width iteration), and
+ /// a cost that does not is proportional to the document itself.
+ position,
};
/// Widths and signed integers do not mix in Zig 0.16: `printIntAny` emits an explicit `+` for any
@@ -328,6 +335,41 @@ fn sweep(port: *serial.Port, o: Options, r: *Report) !void {
try trials(port, o, r, .{ .op = p.name, .keys = p.keys });
}
},
+ // POSITION. One 320-character line, built once, then the cursor is parked at three places
+ // in it and the SAME single-character insert is timed at each. The document never changes,
+ // so anything that moves is a function of where the cursor is, not of how much text exists.
+ .position => {
+ var built: u32 = 0;
+ while (built < 320) {
+ const batch: u32 = @min(8, 320 - built);
+ var fill: [8]u8 = @splat('y');
+ try port.write(fill[0..batch]);
+ _ = try rtt.roundTrip(port, "", 2_000_000, 120_000);
+ built += batch;
+ }
+ // Leave insert mode so `0`, `$` and `h` are motions, then for each position re-enter
+ // insert exactly at it. `i` inserts before the cursor, so the column IS the parked one.
+ try port.write("\x1b");
+ _ = try rtt.roundTrip(port, "", 400_000, 250_000);
+ for ([_]struct { name: []const u8, go: []const u8, col: u32 }{
+ .{ .name = "col_end", .go = "$", .col = 320 },
+ .{ .name = "col_start", .go = "0", .col = 0 },
+ .{ .name = "col_end_again", .go = "$", .col = 320 },
+ }) |p| {
+ try port.write(p.go);
+ _ = try rtt.roundTrip(port, "", 400_000, 250_000);
+ try port.write("i");
+ _ = try rtt.roundTrip(port, "", 400_000, 250_000);
+ try trials(port, o, r, .{ .length = p.col, .op = p.name });
+ // Undo the insertions this condition made, so the next one starts from the same
+ // document. Backspace as many times as there were trials.
+ for (0..@min(o.repeat, 64)) |_| {
+ _ = try rtt.roundTrip(port, "\x7f", 2_000_000, 120_000);
+ }
+ try port.write("\x1b");
+ _ = try rtt.roundTrip(port, "", 400_000, 250_000);
+ }
+ },
}
}