DEV Community

林子篆
林子篆

Posted on • Originally published at dannypsnl.github.io on

5 1

How to compare Go benchmark in TravisCI

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

Frist we create a script called bench_compare.sh:

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 golang.org/x/tools/cmd/benchcmp && \
    benchcmp master_bench.out current_bench.out;
fi
Enter fullscreen mode Exit fullscreen mode

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

script:
  # testing part
after_success:
  # ignore
  - bash ./bench_compare.sh
Enter fullscreen mode Exit fullscreen mode

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 golang.org/x/tools/cmd/benchcmp for comparing, and compare two result file.

To get more info, you can reference:

Thanks for reading

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free