terminal/new: add bench

This commit is contained in:
Mitchell Hashimoto
2024-02-19 21:56:07 -08:00
parent a1c14d1859
commit dc6de51472
5 changed files with 56 additions and 19 deletions

View File

@ -8,7 +8,7 @@
# - "ascii", uniform random ASCII bytes
# - "utf8", uniform random unicode characters, encoded as utf8
# - "rand", pure random data, will contain many invalid code sequences.
DATA="utf8"
DATA="ascii"
SIZE="25000000"
# Uncomment to test with an active terminal state.

View File

@ -15,6 +15,7 @@ const ArenaAllocator = std.heap.ArenaAllocator;
const ziglyph = @import("ziglyph");
const cli = @import("../cli.zig");
const terminal = @import("../terminal/main.zig");
const terminalnew = @import("../terminal/new/main.zig");
const Args = struct {
mode: Mode = .noop,
@ -26,7 +27,7 @@ const Args = struct {
/// Process input with a real terminal. This will be MUCH slower than
/// the other modes because it has to maintain terminal state but will
/// help get more realistic numbers.
terminal: bool = false,
terminal: Terminal = .none,
@"terminal-rows": usize = 80,
@"terminal-cols": usize = 120,
@ -42,6 +43,8 @@ const Args = struct {
if (self._arena) |arena| arena.deinit();
self.* = undefined;
}
const Terminal = enum { none, old, new };
};
const Mode = enum {
@ -91,8 +94,7 @@ pub fn main() !void {
const writer = std.io.getStdOut().writer();
const buf = try alloc.alloc(u8, args.@"buffer-size");
const seed: u64 = if (args.seed >= 0) @bitCast(args.seed)
else @truncate(@as(u128, @bitCast(std.time.nanoTimestamp())));
const seed: u64 = if (args.seed >= 0) @bitCast(args.seed) else @truncate(@as(u128, @bitCast(std.time.nanoTimestamp())));
// Handle the modes that do not depend on terminal state first.
switch (args.mode) {
@ -104,8 +106,8 @@ pub fn main() !void {
// Handle the ones that depend on terminal state next
inline .scalar,
.simd,
=> |tag| {
if (args.terminal) {
=> |tag| switch (args.terminal) {
.old => {
const TerminalStream = terminal.Stream(*TerminalHandler);
var t = try terminal.Terminal.init(
alloc,
@ -119,14 +121,32 @@ pub fn main() !void {
.simd => try benchSimd(reader, &stream, buf),
else => @compileError("missing case"),
}
} else {
},
.new => {
const TerminalStream = terminal.Stream(*NewTerminalHandler);
var t = try terminalnew.Terminal.init(
alloc,
args.@"terminal-cols",
args.@"terminal-rows",
);
var handler: NewTerminalHandler = .{ .t = &t };
var stream: TerminalStream = .{ .handler = &handler };
switch (tag) {
.scalar => try benchScalar(reader, &stream, buf),
.simd => try benchSimd(reader, &stream, buf),
else => @compileError("missing case"),
}
},
.none => {
var stream: terminal.Stream(NoopHandler) = .{ .handler = .{} };
switch (tag) {
.scalar => try benchScalar(reader, &stream, buf),
.simd => try benchSimd(reader, &stream, buf),
else => @compileError("missing case"),
}
}
},
},
}
}
@ -244,3 +264,11 @@ const TerminalHandler = struct {
try self.t.print(cp);
}
};
const NewTerminalHandler = struct {
t: *terminalnew.Terminal,
pub fn print(self: *NewTerminalHandler, cp: u21) !void {
try self.t.print(cp);
}
};

View File

@ -51,12 +51,5 @@ pub usingnamespace if (builtin.target.isWasm()) struct {
test {
@import("std").testing.refAllDecls(@This());
_ = @import("new/hash_map.zig");
_ = @import("new/page.zig");
_ = @import("new/PageList.zig");
_ = @import("new/Screen.zig");
_ = @import("new/Terminal.zig");
_ = @import("new/point.zig");
_ = @import("new/size.zig");
_ = @import("new/style.zig");
_ = @import("new/main.zig");
}

View File

@ -262,7 +262,7 @@ pub fn print(self: *Terminal, c: u21) !void {
// If we're at the column limit, then we need to wrap the next time.
// In this case, we don't move the cursor.
if (self.screen.cursor.x == right_limit) {
self.screen.cursor.pending_wrap = true;
//self.screen.cursor.pending_wrap = true;
return;
}

16
src/terminal/new/main.zig Normal file
View File

@ -0,0 +1,16 @@
const builtin = @import("builtin");
pub const Terminal = @import("Terminal.zig");
test {
@import("std").testing.refAllDecls(@This());
// todo: make top-level imports
_ = @import("hash_map.zig");
_ = @import("page.zig");
_ = @import("PageList.zig");
_ = @import("Screen.zig");
_ = @import("point.zig");
_ = @import("size.zig");
_ = @import("style.zig");
}