Debian Codegraph @

src/uu/tac/BENCHMARKING.md

raw
1 # Benchmarking `tac`
2
3 <!-- spell-checker:ignore wikidatawiki -->
4
5 `tac` is often used to process log files in reverse chronological order, i.e.
6 from newer towards older entries. In this case, the performance target to yield
7 results as fast as possible, i.e. without reading in the whole file that is to
8 be reversed line-by-line. Therefore, a sensible benchmark is to read a large log
9 file containing N lines and measure how long it takes to produce the last K
10 lines from that file.
11
12 Large text files can for example be found in the
13 [Wikipedia database dumps](https://dumps.wikimedia.org/wikidatawiki/latest/),
14 usually sized at multiple gigabytes and comprising more than 100M lines.
15
16 After you have obtained and uncompressed such a file, you need to build `tac`
17 in release mode
18
19 ```shell
20 cargo build --release --package uu_tac
21 ```
22
23 and then you can time how it long it takes to extract the last 10M lines by
24 running
25
26 ```shell
27 /usr/bin/time ./target/release/tac wikidatawiki-20211001-pages-logging.xml | head -n10000000 >/dev/null
28 ```
29
30 For more systematic measurements that include warm-ups, repetitions and comparisons,
31 [Hyperfine](https://github.com/sharkdp/hyperfine) can be helpful.
32 For example, to compare this implementation to the one provided by your distribution run
33
34 ```shell
35 hyperfine "./target/release/tac wikidatawiki-20211001-pages-logging.xml | head -n10000000 >/dev/null" "/usr/bin/tac wikidatawiki-20211001-pages-logging.xml | head -n10000000 >/dev/null"
36 ```