| 1 |
# Benchmarking to measure performance |
| 2 |
|
| 3 |
To compare the performance of the `uutils` version of `head` with the |
| 4 |
GNU version of `head`, you can use a benchmarking tool like |
| 5 |
[hyperfine][0]. On Ubuntu 18.04 or later, you can install `hyperfine` by |
| 6 |
running |
| 7 |
|
| 8 |
```shell |
| 9 |
sudo apt-get install hyperfine |
| 10 |
``` |
| 11 |
|
| 12 |
Next, build the `head` binary under the release profile: |
| 13 |
|
| 14 |
```shell |
| 15 |
cargo build --release -p uu_head |
| 16 |
``` |
| 17 |
|
| 18 |
Now, get a text file to test `head` on. I used the *Complete Works of |
| 19 |
William Shakespeare*, which is in the public domain in the United States |
| 20 |
and most other parts of the world. |
| 21 |
|
| 22 |
```shell |
| 23 |
curl -o shakespeare.txt https://www.gutenberg.org/files/100/100-0.txt |
| 24 |
``` |
| 25 |
|
| 26 |
This particular file has about 170,000 lines, each of which is no longer |
| 27 |
than 96 characters: |
| 28 |
|
| 29 |
```shell |
| 30 |
$ wc -lL shakespeare.txt |
| 31 |
170592 96 shakespeare.txt |
| 32 |
``` |
| 33 |
|
| 34 |
You could use files of different shapes and sizes to test the |
| 35 |
performance of `head` in different situations. For a larger file, you |
| 36 |
could download a [database dump of Wikidata][1] or some related files |
| 37 |
that the Wikimedia project provides. For example, [this file][2] |
| 38 |
contains about 130 million lines. |
| 39 |
|
| 40 |
Finally, you can compare the performance of the two versions of `head` |
| 41 |
by running, for example, |
| 42 |
|
| 43 |
```shell |
| 44 |
hyperfine \ |
| 45 |
"head -n 100000 shakespeare.txt" \ |
| 46 |
"target/release/head -n 100000 shakespeare.txt" |
| 47 |
``` |
| 48 |
|
| 49 |
[0]: https://github.com/sharkdp/hyperfine |
| 50 |
[1]: https://www.wikidata.org/wiki/Wikidata:Database_download |
| 51 |
[2]: https://dumps.wikimedia.org/wikidatawiki/20211001/wikidatawiki-20211001-pages-logging.xml.gz |