Skip to content

Commit 80f5826

Browse files
authored
yes: add BENCHMARKING.md (#12097)
1 parent 20f7af8 commit 80f5826

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/uu/yes/BENCHMARKING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Benchmarking yes
2+
3+
`yes` is a utility printing the provided string and a newline continuously.
4+
The default value `y` is used to skip the common `y/n` prompts provided by scripts.
5+
6+
## Understanding yes
7+
8+
The most simple way to implement `yes` is the `println!` loop. But it is slow since it
9+
calls many write syscalls. So `yes` should print an extended string to few bytes in the loop for
10+
better throughput.
11+
12+
It is difficult to use `hyperfine` for benchmarking `yes` as it has infinite loop.
13+
But you can see throughput of `yes` by `pv` instead:
14+
15+
```shell
16+
yes | pv >/dev/null
17+
```
18+
19+
### `tee()` zero-copy
20+
21+
The `read()` and `write()` based `yes` implementation is much slower than RAM's bandwidth
22+
since those syscalls are copying content of RAM.
23+
24+
On Linux, `tee()` and `splice()` for non-pipe output is used to avoid copying content of RAM.

0 commit comments

Comments
 (0)