Skip to content

Commit

Permalink
Diff benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Dec 18, 2023
1 parent 955e080 commit 36e77a3
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 164 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ jobs:
- name: Test
run: make benchmark

- name: CPU
run: go tool pprof -top cpu.prof
- name: Download previous benchmark data
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark

- name: Memory
run: go tool pprof -top mem.prof
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tool: go
output-file-path: benchmark.txt
external-data-json-path: ./cache/benchmark-data.json
comment-on-alert: true
alert-threshold: "100%"
summary-always: true
auto-push: false
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/pint
/.cover
/memprofile.out
/dist/
/.vscode/
/cmd/pint/bench/rules
27 changes: 22 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,31 @@ cover: test
coverhtml: test
go tool cover -html=$(COVER_PROFILE)

cmd/pint/bench/rules:
$(MAKE) -C cmd/pint/bench fetch

.PHONY: benchmark
benchmark:
benchmark: cmd/pint/bench/rules
go test \
-v \
-count=10 \
-run=none \
-bench=. \
-benchmem \
-cpuprofile cpu.prof \
-memprofile mem.prof \
./cmd/pint
./cmd/pint | tee benchmark.txt

$(GOBIN)/benchstat: tools/benchstat/go.mod tools/benchstat/go.sum
go install -modfile=tools/benchstat/go.mod golang.org/x/perf/cmd/benchstat

.PHONY: benchmark-diff
benchmark-diff: $(GOBIN)/benchstat
git diff --exit-code
$(MAKE) benchmark
mv benchmark.txt new.txt

git fetch origin main
git reset --hard FETCH_HEAD

$(MAKE) benchmark
mv benchmark.txt old.txt

$(GOBIN)/benchstat old.txt new.txt
9 changes: 9 additions & 0 deletions cmd/pint/bench/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
REVISION := 31a27fb9e0e778bd8fe6097aa58c8ea598fe9cec

.PHONE: fetch
fetch:
curl -sL -o archive.tar.gz https://github.com/samber/awesome-prometheus-alerts/archive/$(REVISION).tar.gz
tar -xf archive.tar.gz
rm -fr rules
mv awesome-prometheus-alerts-$(REVISION)/dist/rules rules
rm -fr awesome-prometheus-alerts-$(REVISION) archive.tar.gz
7 changes: 7 additions & 0 deletions cmd/pint/bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Benchmark data

A collection of Prometheus rules copied from
[samber/awesome-prometheus-alerts](https://github.com/samber/awesome-prometheus-alerts)
and used to benchmark pint.

Run `make fetch` first to download and unpack rules into `rules` folder.
47 changes: 47 additions & 0 deletions cmd/pint/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"context"
"log/slog"
"testing"

"github.com/prometheus/client_golang/prometheus"

"github.com/cloudflare/pint/internal/config"
"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/git"
"github.com/cloudflare/pint/internal/log"
)

func BenchmarkFindEntries(b *testing.B) {
log.Setup(slog.LevelError, true)

finder := discovery.NewGlobFinder(
[]string{"bench/rules"},
git.NewPathFilter(nil, nil, nil),
)
for n := 0; n < b.N; n++ {
_, _ = finder.Find()
}
}

func BenchmarkCheckRules(b *testing.B) {
log.Setup(slog.LevelError, true)

finder := discovery.NewGlobFinder(
[]string{"bench/rules"},
git.NewPathFilter(nil, nil, nil),
)
entries, err := finder.Find()
if err != nil {
b.Errorf("Find() error: %s", err)
b.FailNow()
}

ctx := context.Background()
cfg, _ := config.Load("", false)
gen := config.NewPrometheusGenerator(cfg, prometheus.NewRegistry())
for n := 0; n < b.N; n++ {
_, _ = checkRules(ctx, 10, true, gen, cfg, entries)
}
}
154 changes: 0 additions & 154 deletions cmd/pint/lint_test.go

This file was deleted.

7 changes: 7 additions & 0 deletions tools/benchstat/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module _

go 1.21.4

require golang.org/x/perf v0.0.0-20231127181059-b53752263861

require github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 // indirect
4 changes: 4 additions & 0 deletions tools/benchstat/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 h1:xlwdaKcTNVW4PtpQb8aKA4Pjy0CdJHEqvFbAnvR5m2g=
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY=
golang.org/x/perf v0.0.0-20231127181059-b53752263861 h1:oWUgm6RG0ZUKQeX7wxjnX+TFCrXDSheBtpiy5vpUdZg=
golang.org/x/perf v0.0.0-20231127181059-b53752263861/go.mod h1:sKqUfjZtdM78wIFCYFnmu2FhhanvRUbp67Zgmj3TZPM=
7 changes: 7 additions & 0 deletions tools/benchstat/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build tools

package tools

import (
_ "golang.org/x/perf/cmd/benchstat"
)

1 comment on commit 36e77a3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.

Benchmark suite Current: 36e77a3 Previous: e4dcf37 Ratio
BenchmarkFindEntries - ns/op 107649694 ns/op 105918741 ns/op 1.02
BenchmarkFindEntries - B/op 72722530 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540043 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 113862750 ns/op 105918741 ns/op 1.08
BenchmarkFindEntries - B/op 72713478 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540028 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 107934465 ns/op 105918741 ns/op 1.02
BenchmarkFindEntries - B/op 72717778 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540056 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 107229985 ns/op 105918741 ns/op 1.01
BenchmarkFindEntries - B/op 72716580 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540038 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 108577451 ns/op 105918741 ns/op 1.03
BenchmarkFindEntries - B/op 72733831 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540060 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 108884478 ns/op 105918741 ns/op 1.03
BenchmarkFindEntries - B/op 72723761 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540047 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 107979912 ns/op 105918741 ns/op 1.02
BenchmarkFindEntries - B/op 72726291 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540049 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 108059454 ns/op 105918741 ns/op 1.02
BenchmarkFindEntries - B/op 72716228 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540018 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 108098278 ns/op 105918741 ns/op 1.02
BenchmarkFindEntries - B/op 72725500 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540056 allocs/op 539957 allocs/op 1.00
BenchmarkFindEntries - ns/op 109500115 ns/op 105918741 ns/op 1.03
BenchmarkFindEntries - B/op 72725580 B/op 72700400 B/op 1.00
BenchmarkFindEntries - allocs/op 540041 allocs/op 539957 allocs/op 1.00
BenchmarkCheckRules - B/op 133239487 B/op 133233465 B/op 1.00
BenchmarkCheckRules - allocs/op 959661 allocs/op 959608 allocs/op 1.00
BenchmarkCheckRules - ns/op 108450728 ns/op 107024323 ns/op 1.01
BenchmarkCheckRules - allocs/op 959620 allocs/op 959608 allocs/op 1.00
BenchmarkCheckRules - ns/op 107360030 ns/op 107024323 ns/op 1.00
BenchmarkCheckRules - allocs/op 959615 allocs/op 959608 allocs/op 1.00
BenchmarkCheckRules - ns/op 109200169 ns/op 107024323 ns/op 1.02
BenchmarkCheckRules - B/op 133234136 B/op 133233465 B/op 1.00
BenchmarkCheckRules - allocs/op 959636 allocs/op 959608 allocs/op 1.00
BenchmarkCheckRules - ns/op 107863341 ns/op 107024323 ns/op 1.01
BenchmarkCheckRules - ns/op 107738005 ns/op 107024323 ns/op 1.01
BenchmarkCheckRules - ns/op 107360051 ns/op 107024323 ns/op 1.00
BenchmarkCheckRules - allocs/op 959610 allocs/op 959608 allocs/op 1.00
BenchmarkCheckRules - ns/op 107250315 ns/op 107024323 ns/op 1.00
BenchmarkCheckRules - ns/op 107872018 ns/op 107024323 ns/op 1.01
BenchmarkCheckRules - allocs/op 959613 allocs/op 959608 allocs/op 1.00
BenchmarkCheckRules - ns/op 107223347 ns/op 107024323 ns/op 1.00
BenchmarkCheckRules - allocs/op 959616 allocs/op 959608 allocs/op 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.