Skip to content

Commit

Permalink
benchstat each group of benchmarks separately
Browse files Browse the repository at this point in the history
  • Loading branch information
jub0bs committed Jan 10, 2025
1 parent f8429c7 commit 05e6424
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/cors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
10 changes: 6 additions & 4 deletions middleware_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 05e6424

Please sign in to comment.