Skip to content

Commit

Permalink
test: Add match offers benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bgins committed Jan 23, 2025
1 parent 833ff31 commit 9f21ff2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions pkg/solver/matcher/matcher_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build bench && solver

package matcher

import "testing"

func BenchmarkMatchOffers(b *testing.B) {
testCases := generateMatchTestCases()
b.ResetTimer()

for i := 0; i < b.N; i++ {
for _, tc := range testCases {
result := matchOffers(tc.resourceOffer, tc.jobOffer)
if result.matched() != tc.shouldMatch {
b.Fatalf("expected match to be %v for case %s", tc.shouldMatch, tc.name)
}
}
}
}
2 changes: 1 addition & 1 deletion pkg/solver/matcher/testutils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build unit
//go:build unit || bench

package matcher

Expand Down
5 changes: 5 additions & 0 deletions stack
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ function integration-tests-solver() {
load-local-env
go test -v -tags="integration,solver" -count 1 ./...
}

function benchmarks-solver() {
go test -tags="bench,solver" -bench=MatchOffers -benchtime=3s -benchmem ./...
}

############################################################################
# run
#
Expand Down

0 comments on commit 9f21ff2

Please sign in to comment.