DEV Community


How to compare Go benchmark in TravisCI

dannypsnl profile image 林子篆 Originally published at on ・1 min read

Although the article is for Go, but you still can use concept part for others language.

Frist we create a script called

if ["${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}" != "master"]; then
    REMOTE_URL="$(git config --get remote.origin.url)";
    cd ${TRAVIS_BUILD_DIR}/.. && \
    git clone ${REMOTE_URL} "${TRAVIS_REPO_SLUG}-bench" && \
    cd "${TRAVIS_REPO_SLUG}-bench" && \
    git checkout master && \
    go test -bench . ./... > master_bench.out && \
    git checkout ${TRAVIS_COMMIT} && \
    go test -bench . ./... > current_bench.out && \
    go get && \
    benchcmp master_bench.out current_bench.out;

Then I usually would execute it at after_success this section,.travis.yml:

  # testing part
  # ignore
  - bash ./

p.s. write script part is just want to tell you it’s located at that indention

Now let me explain the script, basically we peek ${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} is not master first. To make sure we are not at master branch, if we are not at master, then we start to compare the benchmark result. Here has a point, $(git config --get remote.origin.url) is required, you can write git checkout master to know why. Then we checkout master and ${TRAVIS_COMMIT}(I think this variable already tell you what is it), do benchmarking and store them. Final step we download for comparing, and compare two result file.

To get more info, you can reference:

Thanks for reading

Discussion (0)

Editor guide