Debian Codegraph @

src/uu/split/BENCHMARKING.md

raw
1 <!-- spell-checker:ignore testfile -->
2
3 # Benchmarking to measure performance
4
5 To compare the performance of the `uutils` version of `split` with the
6 GNU version of `split`, you can use a benchmarking tool like
7 [hyperfine][0]. On Ubuntu 18.04 or later, you can install `hyperfine` by
8 running
9
10 ```
11 sudo apt-get install hyperfine
12 ```
13
14 Next, build the `split` binary under the release profile:
15
16 ```
17 cargo build --release -p uu_split
18 ```
19
20 Now, get a text file to test `split` on. The `split` program has three
21 main modes of operation: chunk by lines, chunk by bytes, and chunk by
22 lines with a byte limit. You may want to test the performance of `split`
23 with various shapes and sizes of input files and under various modes of
24 operation. For example, to test chunking by bytes on a large input file,
25 you can create a file named `testfile.txt` containing one million null
26 bytes like this:
27
28 ```
29 printf "%0.s\0" {1..1000000} > testfile.txt
30 ```
31
32 For another example, to test chunking by bytes on a large real-world
33 input file, you could download a [database dump of Wikidata][1] or some
34 related files that the Wikimedia project provides. For example, [this
35 file][2] contains about 130 million lines.
36
37 Finally, you can compare the performance of the two versions of `split`
38 by running, for example,
39
40 ```
41 cd /tmp && hyperfine \
42 --prepare 'rm x* || true' \
43 "split -b 1000 testfile.txt" \
44 "target/release/split -b 1000 testfile.txt"
45 ```
46
47 Since `split` creates a lot of files on the filesystem, I recommend
48 changing to the `/tmp` directory before running the benchmark. The
49 `--prepare` argument to `hyperfine` runs a specified command before each
50 timing run. We specify `rm x* || true` so that the output files from the
51 previous run of `split` are removed before each run begins.
52
53 [0]: https://github.com/sharkdp/hyperfine
54 [1]: https://www.wikidata.org/wiki/Wikidata:Database_download
55 [2]: https://dumps.wikimedia.org/wikidatawiki/20211001/wikidatawiki-20211001-pages-logging.xml.gz