Skip to content

Commit 7e2126d

Browse files
committed
ENH Add benchmarking tooling
1 parent bc561ba commit 7e2126d

File tree

2 files changed

+82
-16
lines changed

2 files changed

+82
-16
lines changed

Makefile

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
.PHONY: static clean
22

33
fna2faa: fna2faa.cpp
4+
@echo "Creating a normal build"
45
g++ -std=c++11 -O3 -o fna2faa fna2faa.cpp
56
strip fna2faa
67

78
static: fna2faa-static
9+
810
fna2faa-static: fna2faa.cpp
11+
@echo "Creating a static build"
912
g++ -std=c++11 -O3 -static -o fna2faa-static fna2faa.cpp
1013
strip fna2faa-static
1114

@@ -55,21 +58,11 @@ test: fna2faa
5558
@echo "DONE"
5659
@echo "No problems found"
5760
clean:
58-
rm -f fna2faa fna2faa-static
61+
rm -f fna2faa fna2faa-static fna2faa-*
5962
rm -f result.stdout result.stderr
6063

61-
benchmark: benchmark-long benchmark-short
62-
63-
benchmark-long: fna2faa fna2faa-static
64-
@echo ">> Running benchmark by piping 8 long sequences (343M nucleotides) <<"
65-
@echo ">>>> Standard build (long sequences) <<<<"
66-
@awk '{if ($$0 !~ /^>/) {for (i=0; i<1000000; i++) print} else {print}}' tests/test.fa | /usr/bin/time -v ./fna2faa --quiet - 1>/dev/null
67-
@echo ">>>> Static build (long sequences) <<<<"
68-
@awk '{a[NR]=$$0}END{for (i=0; i<1000000; i++){for(k in a){print a[k]}}}' tests/test.fa | /usr/bin/time -v ./fna2faa-static --quiet - 1>/dev/null
69-
70-
benchmark-short: fna2faa fna2faa-static
71-
@echo ">> Running benchmark by piping 8M short sequences (343M nucleotides) <<"
72-
@echo ">>>> Standard build (many short sequences) <<<<"
73-
@awk '{a[NR]=$$0}END{for (i=0; i<1000000; i++){for(k in a){print a[k]}}}' tests/test.fa | /usr/bin/time -v ./fna2faa --quiet - 1>/dev/null
74-
@echo ">>>> Static build (many short sequences) <<<<"
75-
@awk '{a[NR]=$$0}END{for (i=0; i<1000000; i++){for(k in a){print a[k]}}}' tests/test.fa | /usr/bin/time -v ./fna2faa-static --quiet - 1>/dev/null
64+
benchmark:
65+
@echo "Benchmarking normal build"
66+
@./benchmark.sh HEAD~1
67+
@echo "Benchmarking static build"
68+
@./benchmark.sh --static HEAD~1

benchmark.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
command -v awk >/dev/null 2>&1 || {
4+
echo "'awk' not found. Aborting benchmark." >&2
5+
exit 1; }
6+
7+
command -v getopt >/dev/null 2>&1 || {
8+
echo "'getopt' not found. Aborting benchmark." >&2
9+
exit 1; }
10+
11+
command -v git >/dev/null 2>&1 || {
12+
echo "'git' not found. Aborting benchmark." >&2
13+
exit 1; }
14+
15+
command -v hyperfine >/dev/null 2>&1 || {
16+
echo "'hyperfine' not found. Aborting benchmark." >&2
17+
exit 1; }
18+
19+
CMD="fna2faa"
20+
21+
# Parse args using getopt (instead of getopts) to allow arguments before options
22+
ARGS=$(getopt -o s: -l static: -n "$0" -- "$@")
23+
# reorganize arguments as returned by getopt
24+
eval set -- "$ARGS"
25+
26+
while true; do
27+
case "$1" in
28+
# Shift before to throw away option
29+
# Shift after if option has a required positional argument
30+
-s|--static)
31+
shift
32+
CMD="fna2faa-static"
33+
shift
34+
;;
35+
--)
36+
shift
37+
break
38+
;;
39+
esac
40+
done
41+
42+
if [ "$#" -ne 1 ]; then
43+
echo "Please specify the commit with which to benchmark against"
44+
exit 1
45+
fi
46+
47+
if [[ -n $(git status --porcelain) ]]; then
48+
echo "!! Warning this script will benchmark the most recent commit against the provided commit. Please commit your changes !!"
49+
exit 1;
50+
fi
51+
52+
COMMIT_PREV="$(git rev-parse --short "$1")"
53+
COMMIT_CURR="$(git rev-parse --short HEAD)"
54+
55+
git worktree remove -f "fna2faa-$COMMIT_PREV-folder"
56+
rm -rf fna2faa "fna2faa-$COMMIT_PREV" "fna2faa-$COMMIT_CURR"
57+
58+
( git worktree add fna2faa-prev-folder "$1" && cd fna2faa-prev-folder && make $CMD && mv fna2faa ../fna2faa-previous && cd .. && git worktree remove -f fna2faa-prev-folder )
59+
make $CMD && mv $CMD fna2faa-current
60+
61+
echo ">> Benchmarking (8 long sequences - 343M nucleotides) <<"
62+
hyperfine \
63+
-n "Current commit $COMMIT_CURR" \
64+
"awk '{if ($$0 !~ /^>/) {for (i=0; i<1000000; i++) print} else {print}}' tests/test.fa | ./fna2faa-current --quiet - 1>/dev/null" \
65+
-n "Previous commit $COMMIT_PREV" \
66+
"awk '{if ($$0 !~ /^>/) {for (i=0; i<1000000; i++) print} else {print}}' tests/test.fa | ./fna2faa-previous --quiet - 1>/dev/null"
67+
68+
echo ">> Benchmarking (8M short sequences - 343M nucleotides) <<"
69+
hyperfine \
70+
-n "Current commit $COMMIT_CURR" \
71+
"awk '{a[NR]=$$0}END{for (i=0; i<1000000; i++){for(k in a){print a[k]}}}' tests/test.fa | ./fna2faa-current --quiet - 1>/dev/null" \
72+
-n "Previous commit $COMMIT_PREV" \
73+
"awk '{a[NR]=$$0}END{for (i=0; i<1000000; i++){for(k in a){print a[k]}}}' tests/test.fa | ./fna2faa-previous --quiet - 1>/dev/null"

0 commit comments

Comments
 (0)