Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add benchmarks workflow #965

Merged
merged 4 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Benchmarks
# Benchmarks workflow runs benchmark tests and compares the results with the ones present on the master branch.
# This workflow is run on pushes to master & every Pull Requests where a .go, .mod, .sum have been changed
on:
pull_request:
push:
branches:
- master

jobs:
Benchmarks:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.17

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.0
with:
PATTERNS: |
**/**.go
go.mod
go.sum

- name: Go cache 💾
if: env.GIT_DIFF
uses: actions/cache@v2
with:
path: ~/go/pkg
key: ${{ runner.os }}-go-pkg-${{ hashFiles('**/go.mod') }}

- name: Restore benchstat 🪛
if: env.GIT_DIFF
uses: actions/cache@v2.1.7
with:
path: ~/go/bin/benchstat
key: ${{ runner.os }}-benchstat

- name: Restore base benchmark result 📝
if: env.GIT_DIFF
uses: actions/cache@v2
with:
path: |
bench-master.txt
# Using base sha for PR or new commit hash for master/main push in benchmark result key.
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}

- name: Run benchmarks 🧮
run: REF_NAME=${GITHUB_REF##*/} make benchmark
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/desmos-labs/desmos.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
BENCH_COUNT ?= 5
REF_NAME ?= $(shell git symbolic-ref HEAD --short | tr / - 2>/dev/null)

export GO111MODULE = on

Expand Down Expand Up @@ -274,7 +276,9 @@ test-cover:
.PHONY: test-cover

benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION)
@go test -mod=readonly -bench=. -count=$(BENCH_COUNT) -run=^a ./... >bench-$(REF_NAME).txt
@test -s $(GOPATH)/bin/benchstat || GO111MODULE=off GOFLAGS= GOBIN=$(GOPATH)/bin go get -u golang.org/x/perf/cmd/benchstat
@test -e bench-master.txt && benchstat bench-master.txt bench-$(REF_NAME).txt || benchstat bench-$(REF_NAME).txt
.PHONY: benchmark

###############################################################################
Expand Down