Skip to content

Commit

Permalink
Introduce benchmarks action
Browse files Browse the repository at this point in the history
As suggested here: #119 (comment)
  • Loading branch information
yosiat committed Oct 30, 2022
1 parent 2e998e2 commit 358cd74
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Benchmarks

on:
push:
branches: ["main"]

pull_request:
branches: ["main"]

jobs:
benchmark:
name: Benchmarks
strategy:
matrix:
go-version: ["1.18"]
platform: ["ubuntu-latest"]

runs-on: ${{ matrix.platform }}
timeout-minutes: 10

steps:
- name: Checkout repository
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b

- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Run benchmark
run: go test -benchmem -run="^$" -bench "^Benchmark" . github.com/timbray/quamina | tee output.txt

- name: Download previous benchmark data
uses: actions/cache@v1
with:
path: ./cache
key: ${{ runner.os }}-benchmark

- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Go Benchmark
tool: "go"

# Compare results against json from cache
output-file-path: output.txt
external-data-json-path: ./cache/benchmark-data.json

# Alert on regression
alert-threshold: "120%"
fail-on-alert: true
comment-on-alert: false

# Disable github pages, for now.
auto-push: false
5 changes: 0 additions & 5 deletions citylots_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package quamina

import (
"testing"
"time"
)

func BenchmarkCityLots(b *testing.B) {
Expand Down Expand Up @@ -37,7 +36,6 @@ func BenchmarkCityLots(b *testing.B) {
lines := getCityLotsLines(b)

b.ResetTimer()
before := time.Now()

for i := 0; i < b.N; i++ {
lineIndex := i
Expand All @@ -54,7 +52,4 @@ func BenchmarkCityLots(b *testing.B) {
}

topMatches = localMatches
elapsed := float64(time.Since(before).Milliseconds())
perSecond := float64(b.N) / (elapsed / 1000.0)
b.Logf("%.2f matches/second, total lines: %d", perSecond, b.N)
}

0 comments on commit 358cd74

Please sign in to comment.