Benchmarks

Bytes per frame

How many bytes each renderer writes to the terminal to go from one frame to the next. Fewer bytes means less work for the terminal and less data over a slow link such as SSH. Byte counts do not depend on the machine: every run gave the same numbers.

What was measured

Five scenarios, each a fixed sequence of 101 frames (a first frame, then 100 more) on an 80x24 screen. The frame text is built the same way in scripts/bench/src/scenario.rs, scripts/bench/go/scenario.go and scripts/bench/verify.py; all three print the same FNV-1a hash of every frame's text, so every implementation draws exactly the same frames.

scenario each frame
counter Count: N and a help line; N goes up by one
list 20 items; a > marker and a bold cyan (SGR) row move down one row (wrapping after the last)
log 24 lines of a log; one new line at the bottom, the oldest drops off the top
spinner one line: a braille spinner glyph that changes, then static text
full 24 rows of 79 letters picked by a hash of column, row and frame; capitals on even frames, small letters on odd ones, so every cell changes and nothing can be scrolled or shifted into place

Each scenario runs inline (below the prompt) and on the alternate screen.

"Mean" is the mean bytes per frame over the 100 frames after the first. "First" is everything written up to and including the first frame, set-up sequences included. Bytes written when the program ends are left out.

How frames were counted

Each step (a key press for petitcarnets, a message for the others) is sent only after the previous step's frame has been written, so two steps never share a frame:

In every run each of the 100 steps produced exactly one flush (Rust) or one Write (Go), no step timed out, and the model saw all 100 steps.

Every run's bytes were also replayed through a small 80x24 terminal model (scripts/bench/verify.py): after each of the 101 frames the screen showed exactly that frame's text, for all 50 runs. Styles are not checked.

Results: inline

Mean bytes per frame, first frame bytes in brackets. Measured again for v0.0.5, after v0.0.4 brought every colour down to the colour profile in the renderer's writer: every number is the same as for v0.0.3, for petitcarnets and for the others (the bench's backend is not a terminal, so the profile is 24-bit colour and nothing is converted).

scenario petitcarnets Bubble Tea v2 (tty) Bubble Tea v2 (no input) charmed-bubbletea bubbletea-rs
counter 4.2 (81) 2.3 (102) 4.3 (62) 57.9 (67) 53.9 (53)
list 31.7 (301) 32.4 (285) 31.4 (227) 241.0 (250) 236.0 (236)
log 659.3 (1281) 1230.4 (1303) 1207.4 (1241) 1258.0 (1267) 1253.0 (1253)
spinner 4.0 (65) 5.0 (87) 5.0 (48) 37.0 (51) 37.0 (37)
full 1948.0 (1978) 1948.0 (2000) 1925.0 (1938) 1954.0 (1963) 1949.0 (1949)

Results: alternate screen

scenario petitcarnets Bubble Tea v2 (tty) Bubble Tea v2 (no input) charmed-bubbletea bubbletea-rs
counter 4.2 (92) 2.2 (118) 4.2 (73) 18.9 (94) 53.9 (53)
list 31.4 (312) 31.4 (301) 30.4 (238) 50.1 (424) 236.0 (236)
log 54.0 (1292) 52.0 (1319) 52.0 (1252) 1455.0 (1477) 1253.0 (1253)
spinner 4.0 (76) 5.0 (103) 5.0 (59) 40.0 (62) 37.0 (37)
full 1945.0 (1988) 1945.0 (2015) 1922.0 (1948) 2151.0 (2173) 1949.0 (1949)

What is and is not apples to apples

Environment

Reproduce

The Rust bench is its own Cargo project (an empty [workspace] keeps it out of the petitcarnets package):

cd scripts/bench
cargo run --release                                  # all three Rust ports
cargo run --release --no-default-features            # petitcarnets only
cargo run --release -- --frames 100 --only petitcarnets --dump /tmp/frames

bubbletea-rs needs a terminal and writes its cursor and alternate screen sequences to stdout; without one (CI, an agent) it reports why and is skipped. To run it without a terminal:

script -qec "cargo run --release" /dev/null > rust.txt

The Go bench is its own module. go.sum has every hash except Bubble Tea's, which -mod=mod adds on the first online run:

cd scripts/bench/go
export GOFLAGS=-mod=mod
go run .                                             # no input
script -qec "go run . -tty" /dev/null > go-tty.txt   # tty

Run the -tty case with script and its output sent to a file, as above, so no terminal answers Bubble Tea's queries: an answer would turn on synchronised output and change the numbers.

Offline, from a Bubble Tea v2.2.0 checkout, point a copy of go.mod at it:

cd scripts/bench/go
{ cat go.mod; echo "replace charm.land/bubbletea/v2 => /path/to/bubbletea"; } > /tmp/offline.mod
GOFLAGS="-mod=mod -modfile=/tmp/offline.mod" GOPROXY=off go run .

To check that every run drew the right screens:

cd scripts/bench
cargo run --release -- --dump /tmp/frames
(cd go && go run . -dump /tmp/frames)
python3 verify.py /tmp/frames

Checked in CI

The "Bytes per frame" job runs petitcarnets alone (no other port, no Go, nothing to download beyond the bench's own lockfile) and fails if any scenario writes a different number of bytes than scripts/bench/expected.tsv records: the first frame, and the 100 frames after it together.

cd scripts/bench
cargo run --release --no-default-features -- --check expected.tsv
cargo run --release --no-default-features -- --bless expected.tsv  # after a change meant to alter them

A renderer change that writes more (or fewer) bytes fails the job until expected.tsv and the tables above are updated with it. The comparison with Bubble Tea and the other ports stays a manual run, as above.

Keystroke latency

Time from writing a key to the first byte of the frame that answers it, in a real pseudo-terminal: scripts/latency.py runs the counter example (release build, alternate screen), presses + 300 times and waits for each frame to finish (20 ms of quiet) before the next press. The frame after a key is drawn at once, not on the next frame tick.

cargo build --release --example counter
python3 scripts/latency.py 300

Four runs on the machine above, 2026-11-27 (the spread between runs is the CPU's power state, not the program):

run median p99 max
1 0.478 ms 0.591 ms 1.295 ms
2 0.486 ms 0.579 ms 0.708 ms
3 0.101 ms 0.538 ms 0.903 ms
4 0.115 ms 0.546 ms 1.496 ms

Every run is under the 2 ms target at the median and at p99. Bubble Tea was not measured this way.