diff --git a/src/bench/page-init.sh b/src/bench/page-init.sh new file mode 100755 index 000000000..f54df627b --- /dev/null +++ b/src/bench/page-init.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# +# This is a trivial helper script to help run the page init benchmark. +# You probably want to tweak this script depending on what you're +# trying to measure. + +# Uncomment to test with an active terminal state. +# ARGS=" --terminal" + +hyperfine \ + --warmup 10 \ + -n alloc \ + "./zig-out/bin/bench-page-init --mode=alloc${ARGS} try benchAlloc(args.count), + } +} + +noinline fn benchAlloc(count: usize) !void { + for (0..count) |_| { + _ = try terminal.new.Page.init(terminal.new.Page.std_capacity); + } +} diff --git a/src/build_config.zig b/src/build_config.zig index 803e3ee4d..742a2b692 100644 --- a/src/build_config.zig +++ b/src/build_config.zig @@ -143,4 +143,5 @@ pub const ExeEntrypoint = enum { bench_stream, bench_codepoint_width, bench_grapheme_break, + bench_page_init, }; diff --git a/src/main.zig b/src/main.zig index 8cad7ec9f..3a5357471 100644 --- a/src/main.zig +++ b/src/main.zig @@ -10,4 +10,5 @@ pub usingnamespace switch (build_config.exe_entrypoint) { .bench_stream => @import("bench/stream.zig"), .bench_codepoint_width => @import("bench/codepoint-width.zig"), .bench_grapheme_break => @import("bench/grapheme-break.zig"), + .bench_page_init => @import("bench/page-init.zig"), }; diff --git a/src/terminal/main.zig b/src/terminal/main.zig index 45da8564e..ab5bad4d6 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -48,8 +48,9 @@ pub usingnamespace if (builtin.target.isWasm()) struct { pub usingnamespace @import("wasm.zig"); } else struct {}; +/// The new stuff. TODO: remove this before merge. +pub const new = @import("new/main.zig"); + test { @import("std").testing.refAllDecls(@This()); - - _ = @import("new/main.zig"); } diff --git a/src/terminal/new/main.zig b/src/terminal/new/main.zig index 93ea0e04e..caf7c1920 100644 --- a/src/terminal/new/main.zig +++ b/src/terminal/new/main.zig @@ -1,6 +1,8 @@ const builtin = @import("builtin"); +const page = @import("page.zig"); pub const Terminal = @import("Terminal.zig"); +pub const Page = page.Page; test { @import("std").testing.refAllDecls(@This()); diff --git a/src/terminal/new/page.zig b/src/terminal/new/page.zig index af3d4d6dc..ce21e6b79 100644 --- a/src/terminal/new/page.zig +++ b/src/terminal/new/page.zig @@ -91,6 +91,16 @@ pub const Page = struct { const grapheme_bytes_default = grapheme_count_default * grapheme_chunk; const GraphemeMap = AutoOffsetHashMap(Offset(Cell), Offset(u21).Slice); + /// The standard capacity for a page that doesn't have special + /// requirements. This is enough to support a very large number of cells. + /// The standard capacity is chosen as the fast-path for allocation. + pub const std_capacity: Capacity = .{ + .cols = 250, + .rows = 250, + .styles = 128, + .grapheme_bytes = 1024, + }; + /// The size of this page. pub const Size = struct { cols: size.CellCountInt, @@ -319,9 +329,10 @@ pub const Cell = packed struct(u64) { // const total_size = alignForward( // usize, // Page.layout(.{ -// .cols = 333, -// .rows = 81, -// .styles = 32, +// .cols = 250, +// .rows = 250, +// .styles = 128, +// .grapheme_bytes = 1024, // }).total_size, // std.mem.page_size, // );