Skip to content

Commit

Permalink
Add benchmark workflow (#1533)
Browse files Browse the repository at this point in the history
* add a protocol benchmark run

* add a benchmark

* improve benchmark action

* update

* try update benchmark workflow
  • Loading branch information
BrendanChou authored May 17, 2024
1 parent a20347d commit 5863dee
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
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

0 comments on commit 5863dee

Please sign in to comment.