| 1 |
<!-- spell-checker:ignore samply flamegraph flamegraphs --> |
| 2 |
# Benchmarking rm |
| 3 |
|
| 4 |
Run `cargo build --release` before benchmarking after you make a change! |
| 5 |
|
| 6 |
## Simple recursive rm |
| 7 |
|
| 8 |
- Get a large tree, for example linux kernel source tree. |
| 9 |
- We'll need to pass a `--prepare` argument, since `rm` deletes the dir each time. |
| 10 |
- Benchmark simple recursive rm with hyperfine: `hyperfine --prepare "cp -r tree tree-tmp" "target/release/coreutils rm -r tree-tmp"`. |
| 11 |
|
| 12 |
## Comparing with GNU rm |
| 13 |
|
| 14 |
Hyperfine accepts multiple commands to run and will compare them. To compare performance with GNU rm |
| 15 |
duplicate the string you passed to hyperfine but remove the `target/release/coreutils` bit from it. |
| 16 |
|
| 17 |
Example: `hyperfine --prepare "cp -r tree tree-tmp" "target/release/coreutils rm -rf tree-tmp"` becomes |
| 18 |
`hyperfine --prepare "cp -r tree tree-tmp" "target/release/coreutils rm -rf tree-tmp" "rm -rf tree-tmp"` |
| 19 |
(This assumes GNU rm is installed as `rm`) |
| 20 |
|
| 21 |
This can also be used to compare with version of rm built before your changes to ensure your change does not regress this. |
| 22 |
|
| 23 |
Here is a `bash` script for doing this comparison: |
| 24 |
|
| 25 |
```shell |
| 26 |
#!/bin/bash |
| 27 |
cargo build --no-default-features --features rm --release |
| 28 |
test_dir="$1" |
| 29 |
hyperfine --prepare "cp -r $test_dir tmp_d" "rm -rf tmp_d" "target/release/coreutils rm -rf tmp_d" |
| 30 |
``` |
| 31 |
|
| 32 |
## Checking system call count |
| 33 |
|
| 34 |
- Another thing to look at would be system calls count using strace (on linux) or equivalent on other operating systems. |
| 35 |
- Example: `strace -c target/release/coreutils rm -rf tree` |
| 36 |
|
| 37 |
## Flamegraph |
| 38 |
|
| 39 |
### samply |
| 40 |
|
| 41 |
[samply](https://github.com/mstange/samply) is one option for simply creating flamegraphs. It uses the Firefox profiler as a UI. |
| 42 |
|
| 43 |
To install: |
| 44 |
```bash |
| 45 |
cargo install samply |
| 46 |
``` |
| 47 |
|
| 48 |
To run: |
| 49 |
|
| 50 |
```bash |
| 51 |
samply record target/release/coreutils rm -rf ../linux |
| 52 |
``` |
| 53 |
|
| 54 |
### Cargo Flamegraph |
| 55 |
|
| 56 |
With Cargo Flamegraph you can easily make a flamegraph of `rm`: |
| 57 |
|
| 58 |
```shell |
| 59 |
cargo flamegraph --cmd coreutils -- rm [additional parameters] |
| 60 |
``` |