|
| 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