1fb6c1f39Sopenharmony_ciThis directory defines a large suite of benchmarks for both the memchr and
2fb6c1f39Sopenharmony_cimemmem APIs in this crate. A selection of "competitor" implementations are
3fb6c1f39Sopenharmony_cichosen. In general, benchmarks are meant to be a tool for optimization. That's
4fb6c1f39Sopenharmony_ciwhy there is so many: we want to be sure we get enough coverage such that our
5fb6c1f39Sopenharmony_cibenchmarks approximate real world usage. When some benchmarks look a bit slower
6fb6c1f39Sopenharmony_cithan we expect (for one reason another), we can use profiling tools to look at
7fb6c1f39Sopenharmony_cicodegen and attempt to improve that case.
8fb6c1f39Sopenharmony_ci
9fb6c1f39Sopenharmony_ciBecause there are so many benchmarks, if you run all of them, you might want to
10fb6c1f39Sopenharmony_cistep away for a cup of coffee (or two). Therefore, the typical way to run them
11fb6c1f39Sopenharmony_ciis to select a subset. For example,
12fb6c1f39Sopenharmony_ci
13fb6c1f39Sopenharmony_ci```
14fb6c1f39Sopenharmony_ci$ cargo bench -- 'memmem/krate/.*never.*'
15fb6c1f39Sopenharmony_ci```
16fb6c1f39Sopenharmony_ci
17fb6c1f39Sopenharmony_ciruns all benchmarks for the memmem implementation in this crate with searches
18fb6c1f39Sopenharmony_cithat never produce any matches. This will still take a bit, but perhaps only a
19fb6c1f39Sopenharmony_cifew minutes.
20fb6c1f39Sopenharmony_ci
21fb6c1f39Sopenharmony_ciRunning a specific benchmark can be useful for profiling. For example, if you
22fb6c1f39Sopenharmony_ciwant to see where `memmem/krate/prebuiltiter/huge-en/common-one-space` is
23fb6c1f39Sopenharmony_cispending all of its time, you would first want to run it (to make sure the code
24fb6c1f39Sopenharmony_ciis compiled):
25fb6c1f39Sopenharmony_ci
26fb6c1f39Sopenharmony_ci```
27fb6c1f39Sopenharmony_ci$ cargo bench -- memmem/krate/prebuiltiter/huge-en/common-one-space
28fb6c1f39Sopenharmony_ci```
29fb6c1f39Sopenharmony_ci
30fb6c1f39Sopenharmony_ciAnd then run it under your profiling tool (I use `perf` on Linux):
31fb6c1f39Sopenharmony_ci
32fb6c1f39Sopenharmony_ci```
33fb6c1f39Sopenharmony_ci$ perfr --callgraph cargo bench -- memmem/krate/prebuiltiter/huge-en/common-one-space --profile-time 3
34fb6c1f39Sopenharmony_ci```
35fb6c1f39Sopenharmony_ci
36fb6c1f39Sopenharmony_ciWhere
37fb6c1f39Sopenharmony_ci[`perfr` is my own wrapper around `perf`](https://github.com/BurntSushi/dotfiles/blob/master/bin/perfr),
38fb6c1f39Sopenharmony_ciand the `--profile-time 3` flag means, "just run the code for 3 seconds, but
39fb6c1f39Sopenharmony_cidon't do anything else." This makes the benchmark harness get out of the way,
40fb6c1f39Sopenharmony_ciwhich lets the profile focus as much as possible on the code being measured.
41fb6c1f39Sopenharmony_ci
42fb6c1f39Sopenharmony_ciSee the README in the `runs` directory for a bit more info on how to use
43fb6c1f39Sopenharmony_ci`critcmp` to look at benchmark data in a way that makes it easy to do
44fb6c1f39Sopenharmony_cicomparisons.
45