Skip to content

Commit

Permalink
Add crude benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkemperman committed Mar 16, 2019
1 parent b333440 commit 8574dfe
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ pip-log.txt
.tox
nosetests.xml
coverage.xml
.mypy_cache
.pytest_cache

# Virtual env
venv

# Translations
*.mo
Expand All @@ -51,8 +56,6 @@ TestResults/Rx.TE.Tests.mdf
TestResults/Rx.TE.Tests_log.ldf
*.user

.mypy_cache

# Cloud9
.c9

Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ matrix:
- sudo apt-get install -y libgirepository1.0-dev gir1.2-gtk-3.0
- pip3 install pycairo pygobject
script:
- coverage run --source=rx setup.py test
after_success:
- coveralls
- coverage run --source=rx setup.py test && coveralls

- os: linux
dist: xenial
Expand Down Expand Up @@ -46,3 +44,5 @@ install:
script:
- python3 setup.py test

after_success:
- ./.travis/bench.sh
109 changes: 109 additions & 0 deletions .travis/bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env bash

# This script runs a subset of unit tests (minus concurrency, which does too
# much hard sleeps to be a useful benchmark) a couple of times, averaging the
# durations as parsed from pytest output.
#
# It does this for each commit-ish passed as commandline arguments, and then
# for the situation we were in when invoked.
#
# Note that this script switches the local git branch. To protect any unsaved
# work when running locally, it does a git stash first, which is popped back
# later. But if you kill the script before it's done, you may end up in
# the wrong branch and/or your work stashed!

testargs="--cache-clear --ignore=tests/test_concurrency"
rounds=2

pop=0
stat=$(git status | head -n 1)
head=$(echo "$stat" | grep -o "[^ ]*$")
refs=$*

if [[ "$TRAVIS" ]]
then

# Compare versus the PR target branch, if any, or just "master" otherwise
if [[ "$TRAVIS_PULL_REQUEST" != false ]]
then
head=$(git log -1 --format=%H)
refs="$TRAVIS_BRANCH"
else
head="$TRAVIS_BRANCH"
refs=master
fi

else

# Running locally: save unsaved work, if any
if [[ "$refs" ]]
then
git stash | grep "^No"
pop=$?
fi

if [[ $(echo "$stat" | grep -v " detached at ") ]]
then
head=$(echo "$stat" | grep -o "[^ ]*$")
fi

fi

echo "head $head"
echo "refs $refs"
echo "stat $stat"
echo "travis branch $TRAVIS_BRANCH"


for branch in $refs $head
do

# Checkout the branch / commit
echo ""
if [[ "$TRAVIS" && "$branch" != "$head" ]]
then
git fetch origin $branch
git checkout origin/"$branch"
else
git checkout "$branch"
if [[ $pop != 0 ]]; then git stash pop; fi
fi

# Do one warm-up round, which doesn't count toward the average
echo -n " - Round 0 (warm-up)"
sec=$(pytest $testargs | grep -o "passed in .* s")
ret=$?
echo -n " | $sec"
if [[ $ret == 0 ]];
then
echo " | OK"
else
echo " | FAIL"
exit $ret
fi

# Main loop
sum=0
for round in $(seq $rounds)
do
echo -n " - Round $round of $rounds"
sec=$(pytest $testargs | grep -o "passed in .* s")
ret=$?
echo -n " | $sec"

sec=$(echo $sec | sed -e "s/[^0-9]//g")
sum=$(($sum + $sec))
avg=$((((($sum * 10) / $round) + 5) / 10))

echo -n " | total $(echo $sum | sed -e "s/\([0-9]\{2\}\)$/.\1/") s"
echo -n " | average $(echo $avg | sed -e "s/\([0-9]\{2\}\)$/.\1/") s"

if [[ $ret == 0 ]]
then
echo " | OK"
else
echo " | FAIL"
exit $ret
fi
done
done

0 comments on commit 8574dfe

Please sign in to comment.