From 05e6424e3065e03028939334d21a916335bd0970 Mon Sep 17 00:00:00 2001 From: jub0bs Date: Fri, 10 Jan 2025 09:01:32 +0100 Subject: [PATCH] benchstat each group of benchmarks separately --- .github/workflows/cors.yml | 18 ++++++++++++------ middleware_bench_test.go | 10 ++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cors.yml b/.github/workflows/cors.yml index 92a539e..ee5dd89 100644 --- a/.github/workflows/cors.yml +++ b/.github/workflows/cors.yml @@ -26,6 +26,8 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} slug: jub0bs/cors benchmark: + # Mostly to compare allocations; + # measurements of execution speed in GitHub Actions are unreliable. needs: test strategy: matrix: @@ -52,13 +54,17 @@ jobs: - name: Run Benchmark (previous) run: | cd previous - go test -run=^$ -bench=. -count=10 . -benchtime 10000x > benchmark.txt + go test -run=^$ -bench=. -count=10 . -benchtime 10000x > bench_results.txt - name: Run Benchmark (new) run: | cd new - go test -run=^$ -bench=. -count=10 . -benchtime 10000x > benchmark.txt - - name: Run benchstat - # Mostly to compare allocations; - # measurements of execution speed in GitHub Actions are unreliable. + go test -run=^$ -bench=. -count=10 . -benchtime 10000x > bench_results.txt + - name: Run benchstat for middleware initialization run: | - benchstat previous/benchmark.txt new/benchmark.txt + benchstat -filter "/type:init" previous/bench_results.txt new/bench_results.txt + - name: Run benchstat for middleware Config method + run: | + benchstat -filter "/type:config" previous/bench_results.txt new/bench_results.txt + - name: Run benchstat for middleware execution + run: | + benchstat -filter "/type:exec" previous/bench_results.txt new/bench_results.txt diff --git a/middleware_bench_test.go b/middleware_bench_test.go index f2768ce..77f1cb4 100644 --- a/middleware_bench_test.go +++ b/middleware_bench_test.go @@ -351,7 +351,8 @@ func BenchmarkMiddleware(b *testing.B) { } } } - b.Run("initialization "+mwbc.desc, f) + desc := fmt.Sprintf("type=init/cfg=%s", mwbc.desc) + b.Run(desc, f) // benchmark config f = func(b *testing.B) { @@ -368,7 +369,8 @@ func BenchmarkMiddleware(b *testing.B) { mw.Config() } } - b.Run("config "+mwbc.desc, f) + desc = fmt.Sprintf("type=config/cfg=%s", mwbc.desc) + b.Run(desc, f) } // benchmark execution @@ -400,7 +402,7 @@ func BenchmarkMiddleware(b *testing.B) { } }) } - desc := fmt.Sprintf("exec %s vs %s", mwbc.desc, bc.desc) + desc := fmt.Sprintf("type=exec/debug=n/cfg=%s/req=%s", mwbc.desc, bc.desc) if mw == nil { b.Run(desc, f) continue @@ -409,8 +411,8 @@ func BenchmarkMiddleware(b *testing.B) { mw.SetDebug(false) b.Run(desc, f) // Run the benchmark in debug mode. - desc = fmt.Sprintf("exec debug %s vs %s", mwbc.desc, bc.desc) mw.SetDebug(true) + desc = fmt.Sprintf("type=exec/debug=y/cfg=%s/req=%s", mwbc.desc, bc.desc) b.Run(desc, f) } }