Skip to content

Commit 587e2ca

Browse files
committed
Add benchmark script, use hyperfine
1 parent 91e5240 commit 587e2ca

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ target
22
comrak-*
33
.vscode
44
.idea
5+
vendor/comrak
6+
vendor/progit
7+
benches/cmark-gfm
8+
benches/comrak-*
9+
benches/pulldown-cmark

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "vendor/cmark-gfm"]
22
path = vendor/cmark-gfm
33
url = https://github.com/kivikakk/cmark-gfm.git
4+
[submodule "vendor/pulldown-cmark"]
5+
path = vendor/pulldown-cmark
6+
url = https://github.com/raphlinus/pulldown-cmark.git

Makefile

+36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
1+
ROOT:=$(shell git rev-parse --show-toplevel)
2+
COMMIT:=$(shell git rev-parse --short HEAD)
3+
MIN_RUNS:=25
4+
15
src/scanners.rs: src/scanners.re
26
re2rust -W -Werror -i --no-generation-date -o $@ $<
37
cargo fmt
48

59
bench:
610
cargo build --release
711
(cd vendor/cmark-gfm/; make bench PROG=../../target/release/comrak)
12+
13+
binaries: build-comrak-branch build-comrak-master build-cmark-gfm build-pulldown-cmark
14+
15+
build-comrak-branch:
16+
cargo build --release
17+
cp ${ROOT}/target/release/comrak ${ROOT}/benches/comrak-${COMMIT}
18+
19+
build-comrak-master:
20+
git clone https://github.com/kivikakk/comrak.git --depth 1 --single-branch ${ROOT}/vendor/comrak || true
21+
cd ${ROOT}/vendor/comrak && \
22+
cargo build --release && \
23+
cp ./target/release/comrak ${ROOT}/benches/comrak-main
24+
25+
build-cmark-gfm:
26+
cd ${ROOT}/vendor/cmark-gfm && \
27+
make && \
28+
cp build/src/cmark-gfm ${ROOT}/benches/cmark-gfm
29+
30+
build-pulldown-cmark:
31+
cd ${ROOT}/vendor/pulldown-cmark && \
32+
cargo build --release && \
33+
cp target/release/pulldown-cmark ${ROOT}/benches/pulldown-cmark
34+
35+
bench-comrak: build-comrak-branch
36+
git clone https://github.com/progit/progit.git ${ROOT}/vendor/progit || true > /dev/null
37+
cd benches && \
38+
hyperfine --prepare 'sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' --warmup 3 --min-runs ${MIN_RUNS} -L binary comrak-${COMMIT} './bench.sh ./{binary}'
39+
40+
bench-all: binaries
41+
git clone https://github.com/progit/progit.git ${ROOT}/vendor/progit || true > /dev/null
42+
cd benches && \
43+
hyperfine --prepare 'sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' --warmup 3 --min-runs ${MIN_RUNS} -L binary comrak-${COMMIT},comrak-main,pulldown-cmark,cmark-gfm './bench.sh ./{binary}' --export-markdown ${ROOT}/bench-output.md

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@ assert_eq!(
197197
</ol>\n");
198198
```
199199

200+
## Benchmarking
201+
202+
For running benchmarks, you will need to [install hyperfine](https://github.com/sharkdp/hyperfine#installation) and optionally cmake.
203+
204+
If you want to just run benchmark for comrak, with current state of repo, you can simply run
205+
```bash
206+
make bench-comrak
207+
```
208+
209+
This will build comrak in release mode, and run benchmark on it. You will see the time measurements as reported by hyperfine in the console.
210+
211+
Makefile also provides a way to run benchmarks for comark current state (with your changes), comrak main branch, cmark-gfm and pulldown-cmark. For this you will need to install cmake. After that make sure that you have set-up the git submodules. In case you have not installed submodules when cloning, you can do it by running
212+
```bash
213+
git submodule update --init
214+
```
215+
216+
After this is done, you can run
217+
```bash
218+
make bench-all
219+
```
220+
221+
which will run benchmarks across all, and report the time take by each as well as relative time.
222+
223+
224+
225+
200226
## Security
201227

202228
As with [`cmark`](https://github.com/commonmark/cmark) and [`cmark-gfm`](https://github.com/github/cmark-gfm#security),

benches/bench.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /bin/bash
2+
3+
PROG=$1
4+
ROOTDIR=$(git rev-parse --show-toplevel)
5+
6+
for lang in ar az be ca cs de en eo es es-ni fa fi fr hi hu id it ja ko mk nl no-nb pl pt-br ro ru sr th tr uk vi zh zh-tw; do \
7+
cat $ROOTDIR/vendor/progit/$lang/*/*.markdown | $PROG > /dev/null
8+
done

vendor/pulldown-cmark

Submodule pulldown-cmark added at 34c2bb5

0 commit comments

Comments
 (0)