mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
bench/resize
This commit is contained in:
@ -1360,7 +1360,7 @@ fn benchSteps(
|
|||||||
.target = target,
|
.target = target,
|
||||||
|
|
||||||
// We always want our benchmarks to be in release mode.
|
// We always want our benchmarks to be in release mode.
|
||||||
.optimize = .Debug,
|
.optimize = .ReleaseFast,
|
||||||
});
|
});
|
||||||
c_exe.linkLibC();
|
c_exe.linkLibC();
|
||||||
if (install) b.installArtifact(c_exe);
|
if (install) b.installArtifact(c_exe);
|
||||||
|
12
src/bench/resize.sh
Executable file
12
src/bench/resize.sh
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Uncomment to test with an active terminal state.
|
||||||
|
# ARGS=" --terminal"
|
||||||
|
|
||||||
|
hyperfine \
|
||||||
|
--warmup 10 \
|
||||||
|
-n new \
|
||||||
|
"./zig-out/bin/bench-resize --mode=new${ARGS}" \
|
||||||
|
-n old \
|
||||||
|
"./zig-out/bin/bench-resize --mode=old${ARGS}"
|
||||||
|
|
110
src/bench/resize.zig
Normal file
110
src/bench/resize.zig
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
//! This benchmark tests the speed of resizing.
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const assert = std.debug.assert;
|
||||||
|
const Allocator = std.mem.Allocator;
|
||||||
|
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||||
|
const cli = @import("../cli.zig");
|
||||||
|
const terminal = @import("../terminal/main.zig");
|
||||||
|
|
||||||
|
const Args = struct {
|
||||||
|
mode: Mode = .old,
|
||||||
|
|
||||||
|
/// The number of times to loop.
|
||||||
|
count: usize = 10_000,
|
||||||
|
|
||||||
|
/// Rows and cols in the terminal.
|
||||||
|
rows: usize = 50,
|
||||||
|
cols: usize = 100,
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Mode = enum {
|
||||||
|
/// The default allocation strategy of the structure.
|
||||||
|
old,
|
||||||
|
|
||||||
|
/// Use a memory pool to allocate pages from a backing buffer.
|
||||||
|
new,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const std_options: std.Options = .{
|
||||||
|
.log_level = .debug,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
// We want to use the c allocator because it is much faster than GPA.
|
||||||
|
const alloc = std.heap.c_allocator;
|
||||||
|
|
||||||
|
// Parse our args
|
||||||
|
var args: Args = .{};
|
||||||
|
defer args.deinit();
|
||||||
|
{
|
||||||
|
var iter = try std.process.argsWithAllocator(alloc);
|
||||||
|
defer iter.deinit();
|
||||||
|
try cli.args.parse(Args, alloc, &args, &iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the modes that do not depend on terminal state first.
|
||||||
|
switch (args.mode) {
|
||||||
|
.old => {
|
||||||
|
var t = try terminal.Terminal.init(alloc, args.cols, args.rows);
|
||||||
|
defer t.deinit(alloc);
|
||||||
|
try benchOld(&t, args);
|
||||||
|
},
|
||||||
|
|
||||||
|
.new => {
|
||||||
|
var t = try terminal.new.Terminal.init(
|
||||||
|
alloc,
|
||||||
|
@intCast(args.cols),
|
||||||
|
@intCast(args.rows),
|
||||||
|
);
|
||||||
|
defer t.deinit(alloc);
|
||||||
|
try benchNew(&t, args);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
noinline fn benchOld(t: *terminal.Terminal, args: Args) !void {
|
||||||
|
// We fill the terminal with letters.
|
||||||
|
for (0..args.rows) |row| {
|
||||||
|
for (0..args.cols) |col| {
|
||||||
|
t.setCursorPos(row + 1, col + 1);
|
||||||
|
try t.print('A');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (0..args.count) |i| {
|
||||||
|
const cols: usize, const rows: usize = if (i % 2 == 0)
|
||||||
|
.{ args.cols * 2, args.rows * 2 }
|
||||||
|
else
|
||||||
|
.{ args.cols, args.rows };
|
||||||
|
|
||||||
|
try t.screen.resizeWithoutReflow(@intCast(rows), @intCast(cols));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
noinline fn benchNew(t: *terminal.new.Terminal, args: Args) !void {
|
||||||
|
// We fill the terminal with letters.
|
||||||
|
for (0..args.rows) |row| {
|
||||||
|
for (0..args.cols) |col| {
|
||||||
|
t.setCursorPos(row + 1, col + 1);
|
||||||
|
try t.print('A');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (0..args.count) |i| {
|
||||||
|
const cols: usize, const rows: usize = if (i % 2 == 0)
|
||||||
|
.{ args.cols * 2, args.rows * 2 }
|
||||||
|
else
|
||||||
|
.{ args.cols, args.rows };
|
||||||
|
|
||||||
|
try t.screen.resizeWithoutReflow(@intCast(rows), @intCast(cols));
|
||||||
|
}
|
||||||
|
}
|
@ -144,6 +144,7 @@ pub const ExeEntrypoint = enum {
|
|||||||
bench_codepoint_width,
|
bench_codepoint_width,
|
||||||
bench_grapheme_break,
|
bench_grapheme_break,
|
||||||
bench_page_init,
|
bench_page_init,
|
||||||
|
bench_resize,
|
||||||
bench_screen_copy,
|
bench_screen_copy,
|
||||||
bench_vt_insert_lines,
|
bench_vt_insert_lines,
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,7 @@ pub usingnamespace switch (build_config.exe_entrypoint) {
|
|||||||
.bench_codepoint_width => @import("bench/codepoint-width.zig"),
|
.bench_codepoint_width => @import("bench/codepoint-width.zig"),
|
||||||
.bench_grapheme_break => @import("bench/grapheme-break.zig"),
|
.bench_grapheme_break => @import("bench/grapheme-break.zig"),
|
||||||
.bench_page_init => @import("bench/page-init.zig"),
|
.bench_page_init => @import("bench/page-init.zig"),
|
||||||
|
.bench_resize => @import("bench/resize.zig"),
|
||||||
.bench_screen_copy => @import("bench/screen-copy.zig"),
|
.bench_screen_copy => @import("bench/screen-copy.zig"),
|
||||||
.bench_vt_insert_lines => @import("bench/vt-insert-lines.zig"),
|
.bench_vt_insert_lines => @import("bench/vt-insert-lines.zig"),
|
||||||
};
|
};
|
||||||
|
@ -2179,3 +2179,26 @@ test "PageList resize (no reflow) empty screen" {
|
|||||||
try testing.expectEqual(@as(usize, 10), cells.len);
|
try testing.expectEqual(@as(usize, 10), cells.len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test "PageList bug" {
|
||||||
|
// const testing = std.testing;
|
||||||
|
// const alloc = testing.allocator;
|
||||||
|
//
|
||||||
|
// var s = try init(alloc, 300, 100, null);
|
||||||
|
// defer s.deinit();
|
||||||
|
// try testing.expect(s.pages.first == s.pages.last);
|
||||||
|
// const page = &s.pages.first.?.data;
|
||||||
|
// for (0..s.rows) |y| {
|
||||||
|
// for (0..s.cols) |x| {
|
||||||
|
// const rac = page.getRowAndCell(x, y);
|
||||||
|
// rac.cell.* = .{
|
||||||
|
// .content_tag = .codepoint,
|
||||||
|
// .content = .{ .codepoint = 'A' },
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Resize
|
||||||
|
// try s.resize(.{ .cols = s.cols * 2, .rows = s.rows * 2, .reflow = false });
|
||||||
|
// try s.resize(.{ .cols = s.cols / 2, .rows = s.rows / 2, .reflow = false });
|
||||||
|
// }
|
||||||
|
Reference in New Issue
Block a user