Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Benchmarks

Architecture considerations

AppCUI never draws directly on the terminal. Every control paints into an internal screen that lives in memory (a Surface), and a backend then writes that screen to the real terminal. Keeping these two steps apart is what makes it possible to run the same application on different terminals, but it also means that “how fast is AppCUI?” is really several different questions.

   keyboard / mouse / timer / resize events
                     │
                     ▼
          ┌──────────────────────┐
          │  Controls and layout │   
          └──────────┬───────────┘
                     │  paint
                     ▼
          ┌──────────────────────┐
          │    Internal screen   │   
          │      (Surface)       │   
          └──────────┬───────────┘
                     │  backend.update_screen(&surface)
                     ▼
          ┌──────────────────────┐
          │       Backend        │   
          │  (surface -> output) │
          └──────────┬───────────┘
                     │  escape sequences, or API calls
                     ▼
          ┌──────────────────────┐
          │  Terminal / console  │   
          └──────────────────────┘

The internal screen

The internal screen is a rectangular grid with the same size as the terminal. Every cell stores a character code, a foreground color, a background color and a set of flags (bold, underline, …). Controls never see the terminal, they only paint into this grid.

AppCUI is event driven. It does not redraw continuously: when something requests a repaint (an input event, a timer tick, a resize, …), the whole control tree is painted into the internal screen and the backend is called once with the finished result. If nothing happens, nothing is painted and nothing is written to the terminal. This matters for benchmarking, because there is no frame loop to measure: a benchmark has to generate events (or timer ticks) to force repaints.

The backend

The backend turns the internal screen into something that the terminal understands. The way it does that is different for each backend. For example:

BackendHow the screen reaches the terminal
windows_vtANSI / VT escape sequences, written to the console. It currently writes the whole screen on every update.
windows_consoleNo escape sequences. It fills an array of console cells and writes the whole region with the Windows console API (WriteConsoleOutputW).
crosstermUses the crossterm library. It keeps a copy of what it has already painted and only sends the cells that have changed.
termiosANSI / VT escape sequences on Unix terminals. Like windows_vt, it currently writes the whole screen on every update.
debugNo terminal at all. It is driven by a script and is used for tests and benchmarks.

The “writes the whole screen” and “only sends changed cells” behaviors describe the current implementations and can change between versions.

Different computations

Because of this split, the time needed to show a frame is the sum of three different costs that depend on different things:

StepWhat it doesDepends on
1. Build the screenProcess events, compute layouts, paint the controls into the internal screen.The controls on screen and how complex they are. It is independent of the backend and of the terminal.
2. Send the screenThe backend converts the internal screen into output and writes it.The screen size, how many cells changed, the backend (and what it sends), how it writes.
3. Show the screenThe terminal parses the output and renders it.The terminal. AppCUI does not control it, but it affects step 2: when the terminal is slower than the application, the write blocks, and the time shows up in the backend call.

These costs are measured in different ways:

  • Step 1 is measured with the debug backend. It produces no output, so the result isolates AppCUI itself: layout, event handling and painting.
  • Steps 2 and 3 can only be measured together, with a real backend running in a real terminal. When AppCUI is built with the BENCHMARKS feature, the runtime measures the time spent inside backend.update_screen(...) and the number of times it was called. That is what the > Update Screen row of the benchmark tool reports.

The following sections use this split: AppCUI performance covers step 1, and Backend performance covers steps 2 and 3.

AppCUI performance

This chapter measures step 1 of the architecture described above: how long AppCUI needs to build the internal screen (layout, painting of the controls, event handling). Nothing is written to a terminal here. The scenarios run on the debug backend, whose update_screen does no work, and the Surface scenarios do not even create an application. The cost of sending the screen to a terminal is measured separately (see Backend performance).

What the scenarios measure

The scenarios below are the ones that run in a suite (Terminal::EntireScreenUpdate is not part of any suite). Duration is always an average per repetition, in milliseconds.

ScenarioWhat it doesWhat it measures
Surface::WriteCharWrites a normal character (A, white on black) into every cell of a surface of the screen size, one write_char call per cell.The raw cost of the primitive that every control uses to paint. It is a clean per-cell cost, with no application involved.
Surface::WriteTransparentCharThe same, but with a transparent character (one that blends with what is already in the cell).The extra cost of blending compared with a plain overwrite.
Sprite::FillSets every cell of a sprite of the screen size with Sprite::set.The lower bound for filling a grid of cells directly, without clipping or blending logic.
Desktop::Screen.Repaint()Starts an application with an empty desktop and forces a repaint on every repetition.The fixed cost of a frame: clearing and painting the desktop, composing the screen and the application loop. Every other application scenario includes this cost.
Panel::NestedA full-size window that contains a chain of nested panels (one inside the other), as deep as the number of elements. A repaint is forced on every repetition.The cost of depth: every panel fills its parent, so the same cells are painted again for every level.
Window::OverlappingAs many sizeable windows as the number of elements, all almost full-screen and shifted by up to 9 cells, so they cover each other. A repaint is forced on every repetition.The cost of overdraw: how the time grows when many large windows are stacked.
Window::ControlsA set of windows (one for every 16 elements) with a menu bar and a mix of controls: check boxes, radio boxes, labels, text field, combo box, color picker, date picker, numeric selector, tab, splitter and a list view. A repaint is forced on every repetition.A realistic mix of controls. Each window has a fixed size (100x20), so this scenario is mostly sensitive to the number of windows, not to the screen size.
TextField::TypeTextA full-screen window with one text field. On every repetition a key is typed into it.The cost of a keyboard event that changes one control and repaints the screen.
Window::DragA 40x12 window is dragged with the mouse from the top-left corner of the screen to the bottom-right one, and back. A repetition is one round trip.The cost of mouse events and of moving a window (the area behind it has to be repainted too).
Button::TabA window filled with buttons (as many as the number of elements). On every repetition the focus moves to the next button with the Tab key.The cost of focus changes: only the old and the new button change, but the screen is composed again.

Some things to keep in mind when reading the results:

  • The scenarios that start an application include its start-up (creating the windows and controls and allocating the screen). This is divided by --times, so it is small, but it is not zero. This is most visible in the extreme suite.
  • Desktop::Screen.Repaint(), Panel::Nested, Window::Overlapping and Window::Controls force a repaint directly. TextField::TypeText, Window::Drag and Button::Tab go through the real event path (key or mouse event, control logic, repaint), so they cost more than a bare repaint at the same size.
  • Values are printed with two decimals, so everything that shows as 0.00 or 0.01 ms is at the resolution limit of the table. Such values can be compared with each other only very roughly, and the debug/release ratio is not computed for them (-).
  • The data below comes from one run of each suite. It was not repeated, so differences of a few percent are noise.

The suites

Each suite runs the same scenarios with 1000 repetitions, but with a different screen size and number of elements:

SuiteScreen sizeElementsTypical meaning
normal120x3020A default-sized terminal with a small application.
full-screen200x6050A maximized terminal on a good monitor.
complex300x100250A very large terminal with a heavy application.
extreme1000x10001000A stress test (1 million cells). It is not a realistic terminal, but it shows how the costs scale.

Results

Every suite was run twice: with a --release build and with a debug (default cargo profile) build. The last column is how many times slower the debug build is. The rows where the release value is too small to be compared (below 0.05 ms) have no ratio.

normal suite (120x30, 20 elements)

ScenarioRelease (ms)Debug (ms)Debug / Release
Surface::WriteChar0.000.08-
Surface::WriteTransparentChar0.000.09-
Sprite::Fill0.000.05-
Desktop::Screen.Repaint()0.000.03-
Panel::Nested0.010.26-
Window::Overlapping0.010.55-
Window::Controls0.000.09-
TextField::TypeText0.000.11-
Window::Drag0.000.18-
Button::Tab0.000.06-

full-screen suite (200x60, 50 elements)

ScenarioRelease (ms)Debug (ms)Debug / Release
Surface::WriteChar0.010.28-
Surface::WriteTransparentChar0.010.34-
Sprite::Fill0.010.18-
Desktop::Screen.Repaint()0.000.10-
Panel::Nested0.071.7024x
Window::Overlapping0.105.3754x
Window::Controls0.010.35-
TextField::TypeText0.010.41-
Window::Drag0.010.79-
Button::Tab0.010.30-

complex suite (300x100, 250 elements)

ScenarioRelease (ms)Debug (ms)Debug / Release
Surface::WriteChar0.030.74-
Surface::WriteTransparentChar0.030.86-
Sprite::Fill0.020.42-
Desktop::Screen.Repaint()0.000.26-
Panel::Nested0.226.7030x
Window::Overlapping1.1874.9864x
Window::Controls0.071.5622x
TextField::TypeText0.010.92-
Window::Drag0.021.81-
Button::Tab0.020.75-

extreme suite (1000x1000, 1000 elements)

ScenarioRelease (ms)Debug (ms)Debug / Release
Surface::WriteChar0.9723.6024x
Surface::WriteTransparentChar1.0125.4025x
Sprite::Fill0.9614.6015x
Desktop::Screen.Repaint()0.2017.5088x
Panel::Nested69.581,918.5028x
Window::Overlapping258.6813,145.0051x
Window::Controls0.6527.2042x
TextField::TypeText0.7641.5055x
Window::Drag1.4572.8050x
Button::Tab0.6132.8054x

How the cost scales

The cost of a frame follows the number of cells that are painted. The tables below are derived from the ones above (the normal suite is left out, as its release values are too small).

Cost of the primitives, in nanoseconds per cell (duration divided by width x height):

Scenariofull-screen (200x60)complex (300x100)extreme (1000x1000)Debug (all sizes)
Surface::WriteChar~0.8~1.0~1.0~23-25
Sprite::Fill~0.8~0.7~1.0~15-16

For Window::Overlapping, almost every window covers the whole screen, so a good model is windows x width x height. The cost per cell per window, in nanoseconds:

SuiteCell paints per frameReleaseDebug
normal72 000~0.14~7.6
full-screen600 000~0.17~9.0
complex7 500 000~0.16~10.0
extreme1 000 000 000~0.26~13.1

The cost per cell stays almost constant over three orders of magnitude, so the model works well. It rises a little in the extreme suite, which is what is expected when the screen (1 million cells) no longer fits in the CPU caches.

For Window::Controls the interesting number is the cost per window. At 1000x1000 the empty desktop alone costs 0.20 ms (release) or 17.5 ms (debug). Subtracting it, a window with its 16 controls costs about 7 microseconds in release (0.45 ms / 62 windows) and about 160 microseconds in debug (9.7 ms / 62 windows).

Conclusions

  • Always measure in release. The debug build is 15x to 90x slower (typically 25x to 55x). The debug numbers are useful only to compare scenarios with each other (and to find regressions), never as absolute values. For example, Window::Overlapping at 1000x1000 needs 13 seconds per frame in debug and 0.26 seconds in release.
  • AppCUI itself is not the bottleneck for realistic screens. In release, every scenario of the normal and full-screen suites is at or below 0.1 ms per repaint, and the heaviest scenario of the complex suite (300x100, 250 overlapping windows) takes 1.18 ms. A frame at 60 FPS has a budget of about 16.7 ms, so building the internal screen uses well under 1% of it for typical applications. Even the debug build stays below 6 ms at 200x60. The time of a real application will be dominated by what happens after update_screen: the backend and the terminal.
  • The cost is driven by the number of cells painted, not by the number of controls. Painting a cell costs about 1 ns (release), and the cost per cell is flat from 3 600 to 1 000 000 cells. Button::Tab with 1000 buttons (0.61 ms) is not much more expensive than an empty desktop plus a window at the same size (TextField::TypeText, 0.76 ms). Adding controls is cheap, but making them cover more screen is not.
  • Overdraw and depth are the only things that really cost. Panel::Nested and Window::Overlapping are the only scenarios that exceed 0.2 ms in release below 1000x1000. Their cost grows like layers x area, which is consistent with every layer being painted in full, back to front, even when it is hidden behind another one. Practical advice: avoid deep chains of full-size containers and many stacked full-screen windows. If these cases ever matter, skipping the painting of hidden areas would be the optimization with the largest effect.
  • Interactivity is cheap. Typing, moving the focus and dragging a window cost about as much as a bare repaint at the same size (0.01 ms at 200x60 and 0.02 ms at 300x100 in release). Dragging is the most expensive of the three (1.45 ms at 1000x1000 in release, around twice TextField::TypeText). This is consistent with its two mouse drags per repetition, each of them moving a window and repainting the cells it uncovers.
  • Transparency is almost free in release. Surface::WriteTransparentChar is within 5% of WriteChar in release and within about 20% in debug. Sprite::Fill is the same as WriteChar in release and 1.5x to 1.8x faster in debug, because it skips the clipping logic.
  • Extreme sizes are still usable. At 1000x1000 (1 million cells) the simple scenarios take between 0.2 and 1.5 ms in release. Only the scenarios that paint the whole screen many times (Panel::Nested, Window::Overlapping) become heavy.

The numbers above say how fast AppCUI is before anything is sent to the terminal. To decide which backend and terminal to use, compare these costs with the ones in Backend performance, where a single update_screen takes between about one and several milliseconds. That is one to two orders of magnitude more than the AppCUI cost of building the frame.

Backend performance

This chapter measures steps 2 and 3 of the architecture described above: what it costs to send the internal screen to the backend and to have the terminal take it. The AppCUI chapter showed that building a frame costs well under a millisecond for realistic screens, so the interesting question here is how long backend.update_screen(...) takes, and how much that depends on the backend and on the terminal.

The scenario

All the results in this chapter come from Terminal::EntireScreenUpdate. It is the only scenario that runs on a real backend and writes to the terminal it was started from. It starts a timer with a 1 ms interval and, on every tick, changes every cell of the screen, so every frame has to be sent in full. This is the worst case for a backend: nothing can be skipped.

For each run the benchmark reports two numbers (see Reading the results in the benchmark tool chapter):

  • Duration: the wall-clock time of the whole run divided by the number of frames. It is the time between two frames.
  • ** > Update Screen**: the time spent inside backend.update_screen(...) per frame. This covers the backend (turning the screen into escape sequences or console calls) and the terminal accepting them, as one box.

Why the Windows numbers are limited to 15-16 ms

AppCUI is event driven: it only paints when something happens, so to produce a continuous stream of frames the scenario uses a timer. The timer thread sleeps with a timeout, and the precision of that sleep is limited by the operating system:

  • On Windows the default timer resolution is about 15.6 ms. A request for 1 ms returns after about 16 ms, so Duration is around 16 ms in every Windows run, whatever the backend is. At most about 62 frames per second can be produced.
  • On Linux (and WSL) the resolution is close to 1 ms, so a frame can follow another very quickly. If a frame takes longer than the timer interval, the frames run back-to-back and the run is limited by the backend and the terminal.

This makes the two platforms different to measure:

  • Saturated runs (WSL, large screens): Duration is only a little larger than > Update Screen. The application is busy sending the screen all the time, so the numbers describe sustained throughput.
  • Timer-bound runs (Windows): Duration is the timer, and > Update Screen is only the part of the 16 ms that was spent sending the frame. It is still a valid cost for one frame, but it says nothing about how many frames per second the backend could sustain, as the application sleeps most of the time. It is also not possible to reach the saturation point simply by making the screen larger: the screens that would be needed are bigger than any monitor can show.

For this reason the comparison below uses > Update Screen (the cost of one frame), and the utilization ( > Update Screen / Duration) is used only to tell if a run was saturated. A value above 90% means saturated.

One more limitation: > Update Screen measures how long the host needed to accept the data, not when the pixels appeared on the screen. A terminal that buffers a lot and renders later can look faster than it is. The values are comparable for the same terminal with different backends, and less so across different terminals.

Test setup

  • Same machine for all the tests. The terminal window was maximized and the same font size was used for the runs that are compared, so that the screen size is the same (a window larger than the monitor can be clipped by the system, which skews the result).
  • WSL: the WSL console, font size 6, screen 542x148, 3000 frames per run. Backends: termios and crossterm.
  • Windows: the classic console (cmd.exe hosted by conhost.exe), screen 537x135. Backends: windows_vt, windows_console and crossterm.
  • Release build.

Results

WSL (542x148 = 80 216 cells, saturated)

BackendDuration (ms)Update Screen (ms)UtilizationPer cell (ns)
termios5.755.5496%69
crossterm11.6911.3697%142

Windows (537x135 = 72 495 cells, timer-bound)

BackendDuration (ms)Update Screen (ms)UtilizationPer cell (ns)
windows_vt16.073.3521%46
windows_console16.115.8837%81
crossterm16.136.2038%86

“Per cell” is > Update Screen divided by the number of cells.

Other runs, with different sizes and conditions. They are useful to see how the cost changes with the size, but they were not made under identical conditions (font and host changed between them), so compare them only inside the same group:

HostBackendScreenDuration (ms)Update Screen (ms)UtilizationPer cell (ns)
WSLtermios200x601.170.5446%45
WSLtermios200x1001.110.7164%36
WSLtermios420x1003.022.8895%69
WSLcrossterm420x1003.183.0897%73
Rio (Windows)windows_vt200x6015.951.016%84
conhost (Windows)windows_console200x6015.9710.6467%887
conhost (Windows)windows_vt200x6015.9810.6967%891
conhost (Windows)crossterm200x6015.9911.3771%948

The terminal is 95-97% of the time

In the saturated WSL runs, > Update Screen is 96% (termios) and 97% (crossterm) of the frame time at 542x148, and 95% and 97% at 420x100. Everything else (the timer, the event loop, building the internal screen, changing the cells) fits in the remaining 3-5%, or about 0.2 ms per frame at 542x148. This matches the AppCUI chapter, where painting a screen of this size costs around 0.1 ms in release.

Two things follow:

  • Making AppCUI itself faster can improve a frame by at most 3-5%. The effort is better spent on what is sent to the terminal.
  • > Update Screen contains both the backend work and the terminal work, and this scenario cannot separate them. For termios the backend part is the formatting of the escape sequences, which is cheap compared to writing them. That the cost per cell is almost the same at 420x100 and 542x148 (69 ns) suggests that the time is proportional to the volume of data that the terminal has to take.

On Windows, > Update Screen is only 21-38% of Duration, because of the 16 ms timer. The 95-97% figure is not measurable there, but the frame cost is 3-6 ms and AppCUI’s part of it is the same 0.1-0.2 ms, so the conclusion is the same.

Comparing the backends

Windows. windows_vt is the fastest: 3.35 ms per frame. windows_console (which writes the whole screen with a single WriteConsoleOutputW call and does not use escape sequences) needs 5.88 ms, which is 1.75 times more, and crossterm needs 6.20 ms, 1.85 times more. The two slower backends are close to each other.

WSL. At 542x148, termios needs 5.54 ms and crossterm 11.36 ms: crossterm is about 2.05 times slower. At 420x100 they are almost the same (2.88 ms and 3.08 ms, 7% apart). The cost per cell of termios is constant between the two sizes (69 ns), while the cost per cell of crossterm doubles (73 ns, then 142 ns). The cause was not measured. It could be the many small writes that crossterm does for every cell, or the larger volume of data, which stops fitting in the CPU caches. It is the first thing to investigate if the crossterm backend has to be made faster.

Two things should be remembered when reading the comparison:

  • This scenario changes every cell, which is the best case for termios and windows_vt (they send the whole screen anyway) and the worst case for crossterm, which compares the screen with the previous one and sends only the cells that changed. In a real application, where one frame usually changes a small part of the screen, crossterm sends much less data than in this test. This has not been measured yet.
  • The terminal matters as much as the backend. The same backend ranged from 1 ms to more than 10 ms in the tables above, depending on the host.
Best whenWatch out for
windows_vtWindows, when the highest throughput for a full redraw mattersSends the whole screen every frame
windows_consoleWindows consoles where escape sequences are not available16 colors only, cost proportional to the number of cells
termiosLinux, macOS and WSLSends the whole screen every frame
crosstermWhen portability matters, or when frames change only a small part of the screenAbout twice as slow as termios for a full-screen redraw on a very large screen

Conclusions

  • The cost of a frame is the cost of the terminal. 95-97% of the time of a frame in a saturated run is spent in the backend and the terminal. AppCUI’s own work is a few percent.
  • The time needed to show a frame is small. Averaged over the five controlled runs above (very large screens of 72 000 to 80 000 cells), > Update Screen is 6.5 ms per frame, and the average cost per cell is about 85 ns (from 46 ns for windows_vt to 142 ns for crossterm on WSL). Even the slowest case, crossterm on WSL at 542x148 with every cell changing, takes 11.4 ms, which is less than the 16.7 ms of a 60 FPS frame.
  • Typical screens are much cheaper. Scaling the average per-cell cost to common sizes gives about 0.3 ms for 120x30 (3 600 cells) and about 1 ms for 200x60 (12 000 cells). The 200x60 value agrees with the measured 0.54 ms (termios, WSL) and 1.01 ms (Rio). These are estimates based on a straight scaling; they have to be confirmed by measuring at those sizes.
  • Applications change only part of the screen between frames, so in practice the cost is lower than the figures above, which are a worst case (every cell changes, every frame).
  • Choosing a backend: on Windows prefer windows_vt, on Linux and macOS prefer termios. Use crossterm when portability is more important than the last millisecond. The choice of terminal can matter more than the choice of backend.

Benchmark tool

The benchmark project (in the benchmark folder of the repository) is a command line tool that runs a set of scenarios and prints how long each of them takes. It is a normal member of the cargo workspace and uses AppCUI with the BENCHMARKS feature (which collects the timing statistics) and the CROSSTERM feature (so that the crossterm backend can be selected).

Building and running

Always use a release build. Timings from a debug build measure unoptimized code and are not meaningful.

cargo run --release -p benchmark -- <command> [arguments]

or, after building it once, run the executable directly (target/release/benchmark on Linux and macOS, target\release\benchmark.exe on Windows):

benchmark <command> [arguments]

Running it without arguments prints the help text.

All arguments are converted to lowercase before they are parsed, including file names. On case-sensitive file systems, use lowercase names for --output-file.

Commands

CommandWhat it does
helpShows the help text.
list [options]Lists the available benchmarks (and suites). --filter can be used to narrow the list.
run [options]Runs the benchmarks that match the options and prints a results table.
suite <name>Runs a predefined group of benchmarks with fixed parameters (see below).

Options

OptionDefaultDescription
--filter <text>empty (all)Runs only the benchmarks whose name contains <text> (case insensitive). For example --filter window runs Window::Drag, Window::Controls and Window::Overlapping.
--times <count>10How many times the benchmark is repeated (iterations, repaints or frames, depending on the scenario). Must be greater than 0. Use a few hundred or more for stable results.
--screen-size <width>x<height>180x60The size of the screen, between 1 and 1000 for each dimension.
--elements-count <count>50The number of elements (buttons, labels, …) that scenarios with many controls create. Must be greater than 0.
--show-screenoffScenarios driven by a debug script also print the screen after each step. Useful to check what a scenario does. It slows the run down a lot, so do not use it for measurements.
--output-file <file>noneWrites the results table to the file instead of printing it. Progress messages are still printed to the console.
--backend <name>the default oneThe backend used by scenarios that run on a real terminal. Valid names: windows-console and windows-vt (Windows only), termios (Unix only) and crossterm.
--use-terminal-screen-sizeoffDoes not change the size of the terminal. The scenario uses the current size of the terminal instead of --screen-size, and the table reports the size that was actually used.

--backend and --use-terminal-screen-size are only used by scenarios that run on a real terminal (currently Terminal::EntireScreenUpdate).

Scenarios

The scenarios fall into three groups, matching the architecture described above:

GroupScenarioDescription
Surface only (no application)Surface::WriteCharWrite normal chars to a surface.
Surface::WriteTransparentCharWrite transparent chars to a surface.
Sprite::FillFill a sprite with a character.
Application on the debug backend (script driven, no terminal)Desktop::Screen.Repaint()An empty desktop.
Panel::NestedNested panels inside a window.
Window::OverlappingWindows overlapping each other on a screen.
Window::ControlsWindows with different controls (list, buttons, checkboxes, etc.).
TextField::TypeTextType various chars into a text field.
Window::DragDrag a window from one position to another and back.
Button::TabMove focus between buttons with the Tab key.
Application on a real backend and terminalTerminal::EntireScreenUpdateUpdate the entire screen every 1 ms.

The first two groups never write to a terminal, so they measure AppCUI itself (step 1 in the architecture section). Terminal::EntireScreenUpdate is the only scenario that writes to the terminal it is started in, so it also measures the backend and the terminal (steps 2 and 3). It takes over the terminal, so do not touch or resize the window while it runs.

Suites

A suite runs all the scenarios of the first two groups with fixed parameters (1000 repetitions). Terminal::EntireScreenUpdate is not part of any suite.

SuiteScreen sizeElements per application
normal120x3020
full-screen200x6050
complex300x100250
extreme1000x10001000

Reading the results

The results are printed as a table (or written to the --output-file):

Benchmark outputs:
 +--------------------------------+-------------+-----------+----------------------------------------------
 | Test Name                      |  Duration   | Scr. Size | Description
 +--------------------------------+-------------+-----------+----------------------------------------------
 | Terminal::EntireScreenUpdate   |     3.02 ms | 420x100   | Update the entire screen every 1ms
 |  > Update Screen               |     2.88 ms | 420x100   | The time taken to update the screen
 +--------------------------------+-------------+-----------+----------------------------------------------
  • Duration is an average per repetition, in milliseconds. For scenarios that start an application, it is the total time the application ran divided by --times, so it includes the start-up and the first paint. With a small --times this inflates the average, which is another reason to use a larger value.
  • > Update Screen is printed under every scenario that starts an application. It is the total time spent in backend.update_screen(...) divided by the number of screen updates (which can differ slightly from --times). For scenarios on the debug backend this is only the cost of the (empty) debug backend. For Terminal::EntireScreenUpdate it is the time the backend and the terminal need to take one frame.
  • Scr. Size is the size of the screen used by the scenario. For Terminal::EntireScreenUpdate it is the real size of the terminal.

The results depend on the machine, so only compare numbers that were obtained on the same machine, with the same terminal, font and window size, and the same --times.

Notes on Terminal::EntireScreenUpdate

This scenario starts a timer with a 1 ms interval and changes every cell of the screen on each tick, so that every frame has to be sent to the terminal in full. Keep in mind that:

  • The ticks cannot come faster than the timer resolution of the operating system. On Windows the default resolution is around 15.6 ms, so the Duration column stays close to 16 ms however fast the backend is.
  • Compare > Update Screen with Duration. If the first one is much smaller, the application is mostly waiting for the next tick and the run is limited by the timer. If it is close to Duration (for example above 90%), frames are produced back-to-back and the number reflects how fast the backend and the terminal can take a frame.
  • The size of the terminal matters. A larger screen means more work per frame, which makes it easier to go past the timer limit. Use --use-terminal-screen-size on terminals where the application cannot resize the window, and use the same font and window size for runs that you want to compare.

Examples

List all benchmarks and suites:

benchmark list

Run every scenario whose name contains window, 500 times each, at 200x60:

benchmark run --filter window --times 500 --screen-size 200x60

Run a predefined suite:

benchmark suite full-screen

Measure the real terminal with the crossterm backend, using the size of the current window, and save the results:

benchmark run --filter terminal --times 1000 --backend crossterm --use-terminal-screen-size --output-file crossterm.txt