From d1c28c2f4ebf1ba6a2084f0a1a44011daeb42277 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Thu, 30 Apr 2026 22:37:40 +0900 Subject: [PATCH] yes: add BENCHMARKING.md --- src/uu/yes/BENCHMARKING.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/uu/yes/BENCHMARKING.md diff --git a/src/uu/yes/BENCHMARKING.md b/src/uu/yes/BENCHMARKING.md new file mode 100644 index 0000000000..d8fa624865 --- /dev/null +++ b/src/uu/yes/BENCHMARKING.md @@ -0,0 +1,24 @@ +# Benchmarking yes + +`yes` is a utility printing the provided string and a newline continuously. +The default value `y` is used to skip the common `y/n` prompts provided by scripts. + +## Understanding yes + +The most simple way to implement `yes` is the `println!` loop. But it is slow since it +calls many write syscalls. So `yes` should print an extended string to few bytes in the loop for +better throughput. + +It is difficult to use `hyperfine` for benchmarking `yes` as it has infinite loop. +But you can see throughput of `yes` by `pv` instead: + +```shell +yes | pv >/dev/null +``` + +### `tee()` zero-copy + +The `read()` and `write()` based `yes` implementation is much slower than RAM's bandwidth +since those syscalls are copying content of RAM. + +On Linux, `tee()` and `splice()` for non-pipe output is used to avoid copying content of RAM.