Skip to content

Commit 216848f

Browse files
authored
Merge pull request #326 from YJDoc2/add-bench-ci
Add CI for running benchmarks
2 parents 91e5240 + e72e9a7 commit 216848f

File tree

9 files changed

+130
-2
lines changed

9 files changed

+130
-2
lines changed

.github/workflows/benchmarks.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: benchmarks
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
issue_comment:
9+
types:
10+
- created
11+
12+
jobs:
13+
run_benchmarks:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
pull-requests: write
17+
# run either when pull request is opened or when comment body (only on pr) is /run-bench
18+
if: (github.event_name == 'pull_request') || ((github.event.issue.pull_request != null) && github.event.comment.body == '/run-bench')
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
submodules: true
23+
- name: Setup Rust toolchain
24+
uses: dtolnay/rust-toolchain@stable
25+
- name: Install hyperfine
26+
run: cargo install hyperfine
27+
- name: Install cmake
28+
run: sudo apt-get update && sudo apt-get install cmake -y
29+
- name: Build Binaries
30+
run: make binaries
31+
- name: Run Benchmarks
32+
run: make bench-all
33+
- name: Post result comment
34+
uses: mshick/add-pr-comment@v2
35+
with:
36+
message-path: bench-output.md

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ target
22
comrak-*
33
.vscode
44
.idea
5+
vendor/comrak
6+
vendor/progit
7+
benches/cmark-gfm
8+
benches/comrak-*
9+
benches/pulldown-cmark
10+
benches/markdown-it

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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
7+
[submodule "vendor/markdown-it"]
8+
path = vendor/markdown-it
9+
url = https://github.com/rlidwka/markdown-it.rs.git

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,50 @@
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 build-markdown-it
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-markdown-it:
31+
cd ${ROOT}/vendor/markdown-it && \
32+
cargo build --release && \
33+
cp target/release/markdown-it ${ROOT}/benches/markdown-it
34+
35+
build-pulldown-cmark:
36+
cd ${ROOT}/vendor/pulldown-cmark && \
37+
cargo build --release && \
38+
cp target/release/pulldown-cmark ${ROOT}/benches/pulldown-cmark
39+
40+
bench-comrak: build-comrak-branch
41+
git clone https://github.com/progit/progit.git ${ROOT}/vendor/progit || true > /dev/null
42+
cd benches && \
43+
hyperfine --warmup 3 --min-runs ${MIN_RUNS} -L binary comrak-${COMMIT} './bench.sh ./{binary}'
44+
45+
bench-all: binaries
46+
git clone https://github.com/progit/progit.git ${ROOT}/vendor/progit || true > /dev/null
47+
cd benches && \
48+
hyperfine --warmup 10 --min-runs ${MIN_RUNS} -L binary comrak-${COMMIT},comrak-main,pulldown-cmark,cmark-gfm,markdown-it './bench.sh ./{binary}' --export-markdown ${ROOT}/bench-output.md &&\
49+
echo "\n\nRun on" `date -u` >> ${ROOT}/bench-output.md
50+

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,33 @@ 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 the benchmark for `comrak`, with the current state of the 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 `comrak` current state (with your changes), `comrak` main branch, [`cmark-gfm`](https://github.com/github/cmark-gfm), [`pulldown-cmark`](https://github.com/raphlinus/pulldown-cmark) and [`markdown-it.rs`](https://github.com/rlidwka/markdown-it.rs). 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+
Apart from this, CI is also setup for running benchmarks when a pull request is first opened. It will add a comment with the results on the pull request in a tabular format comparing the 5 versions. After that you can manually trigger this CI by commenting `/run-bench` on the PR, this will update the existing comment with new results. Note benchmarks won't be automatically run on each push.
224+
225+
226+
200227
## Security
201228

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

benches/bench.sh

Lines changed: 8 additions & 0 deletions
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/markdown-it

Submodule markdown-it added at c2919dd

vendor/pulldown-cmark

Submodule pulldown-cmark added at 34c2bb5

0 commit comments

Comments
 (0)