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

Add benchmark workflow #1533

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 46 additions & 0 deletions .github/workflows/protocol-benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Protocol Benchmark
on: # yamllint disable-line rule:truthy
pull_request:
paths:
- 'protocol/lib/**'
push:
branches:
- main
- 'release/protocol/v[0-9]+.[0-9]+.x' # e.g. release/protocol/v0.1.x
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x
paths:
- 'protocol/lib/**'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
benchmark:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./protocol
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: 1.22
- name: Run Benchmarks
run: make benchmark | tee ./benchmark_output.txt
- name: Download previous benchmark data
uses: actions/cache@v4
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
tool: 'go'
output-file-path: ./protocol/benchmark_output.txt
external-data-json-path: ./cache/benchmark-data.json
fail-on-alert: true
alert-threshold: '150%'
save-data-file: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
4 changes: 2 additions & 2 deletions protocol/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ test-unit-and-integration:
@VERSION=$(VERSION) go test -mod=readonly -tags='integration_test test_ledger_mock $(build_tags)' ./...

benchmark:
@VERSION=$(VERSION) go test -mod=readonly -tags='$(build_tags)' -bench=. ./...
@VERSION=$(VERSION) go test -mod=readonly -tags='$(build_tags)' -run=^# -bench=. -benchtime=5s -benchmem ./...

test-container:
@SKIP_DISABLED=true VERSION=$(VERSION) go test -mod=readonly -tags='container_test $(build_tags)' ./...
Expand Down Expand Up @@ -421,6 +421,6 @@ update-sample-pregenesis:
check-sample-pregenesis-up-to-date:
$(MAKE) localnet-build
@docker build . -t check-sample-pregenesis -f scripts/genesis/Dockerfile --no-cache
@docker run -v $(CURDIR):/workspace check-sample-pregenesis
@docker run -v $(CURDIR):/workspace check-sample-pregenesis

.PHONY: update-sample-pregenesis check-sample-pregenesis-up-to-date
10 changes: 10 additions & 0 deletions protocol/lib/big_math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ func TestBigRatMulPpm(t *testing.T) {
}
}

func BenchmarkBigRatMulPpm(b *testing.B) {
input := big.NewRat(1_000_000, 1_234_567)
ppm := uint32(5)
var result *big.Rat
for i := 0; i < b.N; i++ {
result = lib.BigRatMulPpm(input, ppm)
}
require.Equal(b, big.NewRat(5, 1_234_567), result)
}

func TestBigRatClamp(t *testing.T) {
tests := map[string]struct {
input *big.Rat
Expand Down
Loading