mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-19 18:26:13 +03:00

This commit adds a few new mode flags to the `bench-stream` program to generator synthetic OSC sequences. The new modes are `gen-osc`, `gen-osc-valid`, and `gen-osc-invalid`. The `gen-osc` mode generates equal parts valid and invalid OSC sequences, while the suffixed variants are for generating only valid or invalid sequences, respectively. This commit also fixes our build system to actually be able to build the benchmarks. It turns out we were just rebuilding the main Ghostty binary for `-Demit-bench`. And, our benchmarks didn't run under Zig 0.14, which is now fixed. An important new design I'm working towards in this commit is to split out synthetic data generation to a dedicated package in `src/bench/synth` although I'm tempted to move it to `src/synth` since it may be useful outside of benchmarks. The synth package is a work-in-progress, but it contains a hint of what's to come. I ultimately want to able to generate all kinds of synthetic data with a lot of knobs to control dimensionality (e.g. in the case of OSC sequences: valid/invalid, length, operation types, etc.).
72 lines
1.9 KiB
Zig
72 lines
1.9 KiB
Zig
//! This benchmark tests the throughput of the terminal escape code parser.
|
|
//!
|
|
//! To benchmark, this takes an input stream (which is expected to come in
|
|
//! as fast as possible), runs it through the parser, and does nothing
|
|
//! with the parse result. This bottlenecks and tests the throughput of the
|
|
//! parser.
|
|
//!
|
|
//! Usage:
|
|
//!
|
|
//! "--f=<path>" - A file to read to parse. If path is "-" then stdin
|
|
//! is read. Required.
|
|
//!
|
|
|
|
const std = @import("std");
|
|
const ArenaAllocator = std.heap.ArenaAllocator;
|
|
const cli = @import("../cli.zig");
|
|
const terminal = @import("../terminal/main.zig");
|
|
|
|
pub fn main() !void {
|
|
// Just use a GPA
|
|
const GPA = std.heap.GeneralPurposeAllocator(.{});
|
|
var gpa = GPA{};
|
|
defer _ = gpa.deinit();
|
|
const alloc = gpa.allocator();
|
|
|
|
// Parse our args
|
|
var args: Args = args: {
|
|
var args: Args = .{};
|
|
errdefer args.deinit();
|
|
var iter = try cli.args.argsIterator(alloc);
|
|
defer iter.deinit();
|
|
try cli.args.parse(Args, alloc, &args, &iter);
|
|
break :args args;
|
|
};
|
|
defer args.deinit();
|
|
|
|
// Read the file for our input
|
|
const file = file: {
|
|
if (std.mem.eql(u8, args.f, "-"))
|
|
break :file std.io.getStdIn();
|
|
|
|
@panic("file reading not implemented yet");
|
|
};
|
|
|
|
// Read all into memory (TODO: support buffers one day)
|
|
const input = try file.reader().readAllAlloc(
|
|
alloc,
|
|
1024 * 1024 * 1024 * 1024 * 16, // 16 GB
|
|
);
|
|
defer alloc.free(input);
|
|
|
|
// Run our parser
|
|
var p: terminal.Parser = .{};
|
|
for (input) |c| {
|
|
const actions = p.next(c);
|
|
//std.log.warn("actions={any}", .{actions});
|
|
_ = actions;
|
|
}
|
|
}
|
|
|
|
const Args = struct {
|
|
f: []const u8 = "-",
|
|
|
|
/// This is set by the CLI parser for deinit.
|
|
_arena: ?ArenaAllocator = null,
|
|
|
|
pub fn deinit(self: *Args) void {
|
|
if (self._arena) |arena| arena.deinit();
|
|
self.* = undefined;
|
|
}
|
|
};
|