| 1 |
#!/bin/bash |
| 2 |
set -eu |
| 3 |
cd "$( dirname "${BASH_SOURCE[0]}" )/.." |
| 4 |
|
| 5 |
main() { |
| 6 |
local python="$(which python)" |
| 7 |
local base="master" |
| 8 |
while [[ $# -gt 0 ]] ; do |
| 9 |
case $1 in |
| 10 |
-h*|--help) |
| 11 |
echo "usage: $(basename $0) [-python $python] [-base master] [-- benchmarks runner args]" >&2 |
| 12 |
exit 0 |
| 13 |
;; |
| 14 |
-base) |
| 15 |
shift |
| 16 |
base="$1" |
| 17 |
;; |
| 18 |
-python) |
| 19 |
shift |
| 20 |
python="$1" |
| 21 |
if [[ -d "$python" ]] ; then |
| 22 |
echo ". assume $python is virtualenv" >&2 |
| 23 |
python="$python/bin/python" |
| 24 |
fi |
| 25 |
if [[ ! -x "$python" ]] ; then |
| 26 |
echo "error: invalid python path: $python" >&2 |
| 27 |
exit 1 |
| 28 |
fi |
| 29 |
;; |
| 30 |
--) |
| 31 |
shift |
| 32 |
break |
| 33 |
;; |
| 34 |
esac |
| 35 |
shift |
| 36 |
done |
| 37 |
|
| 38 |
local benchmark_args="$@" |
| 39 |
local run_benchmarks="$python -m benchmarks $benchmark_args" |
| 40 |
local bnames="" |
| 41 |
if ! bnames=$($run_benchmarks -collect) ; then |
| 42 |
echo "$bnames" >&2 |
| 43 |
exit 1 |
| 44 |
fi |
| 45 |
|
| 46 |
echo "- run benchmarks for new code" >&2 |
| 47 |
for n in $bnames ; do $run_benchmarks -filter "$n\$" ; done >.bench-new.txt |
| 48 |
|
| 49 |
local stashed=0 |
| 50 |
if [[ -n "$(git status --short -uall)" ]] ; then |
| 51 |
echo ". git tree is not clean, will stash." >&2 |
| 52 |
echo ". If stash is not working for you, commit changes first." >&2 |
| 53 |
git stash save --include-untracked |
| 54 |
stashed=1 |
| 55 |
echo "" >&2 |
| 56 |
fi |
| 57 |
echo "- checkout baseline code" >&2 |
| 58 |
git checkout "$base" -- eventlet/ |
| 59 |
echo "- run benchmarks for baseline code" >&2 |
| 60 |
for n in $bnames ; do $run_benchmarks -filter "$n\$" ; done >.bench-base.txt |
| 61 |
|
| 62 |
echo "- return new code back" >&2 |
| 63 |
git checkout . |
| 64 |
[[ "$stashed" -eq 1 ]] && git stash pop |
| 65 |
|
| 66 |
echo "- benchcmp" >&2 |
| 67 |
if ! which benchcmp &>/dev/null ; then |
| 68 |
echo "! benchcmp is not installed, trying go get" >&2 |
| 69 |
if ! which go &>/dev/null ; then |
| 70 |
echo "! go is not installed https://golang.org/doc/install" >&2 |
| 71 |
exit 1 |
| 72 |
fi |
| 73 |
go get golang.org/x/tools/cmd/benchcmp |
| 74 |
fi |
| 75 |
benchcmp .bench-{base,new}.txt |
| 76 |
rm .bench-{base,new}.txt |
| 77 |
} |
| 78 |
|
| 79 |
main "$@" |