mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-20 16:19:33 +00:00
util/sets: benchmark List()
the new implementation based on slices.Sort is 1.7x faster
goos: darwin
goarch: arm64
pkg: k8s.io/apimachinery/pkg/util/sets
cpu: Apple M2 Pro
│ master.txt │ pr-125140.txt │
│ sec/op │ sec/op vs base │
ListSmall-12 305.1n ± 4% 235.0n ± 4% -22.98% (p=0.000 n=8)
ListLarge-12 968.2µ ± 1% 581.5µ ± 0% -39.94% (p=0.000 n=8)
geomean 17.19µ 11.69µ -31.98%
│ master.txt │ pr-125140.txt │
│ B/op │ B/op vs base │
ListSmall-12 184.0 ± 0% 160.0 ± 0% -13.04% (p=0.000 n=8)
ListLarge-12 104.0Ki ± 0% 104.0Ki ± 0% -0.02% (p=0.000 n=8)
geomean 4.323Ki 4.031Ki -6.76%
│ master.txt │ pr-125140.txt │
│ allocs/op │ allocs/op vs base │
ListSmall-12 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=8)
ListLarge-12 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=8)
geomean 2.000 1.000 -50.00%
This commit is contained in:
@@ -356,3 +356,20 @@ func TestIntersection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkListSmall(b *testing.B) {
|
||||
s := sets.New("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")
|
||||
for b.Loop() {
|
||||
sets.List(s)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkListLarge(b *testing.B) {
|
||||
s := make(sets.Set[int], 12345)
|
||||
for i := range 12345 {
|
||||
s.Insert(i * 7)
|
||||
}
|
||||
for b.Loop() {
|
||||
sets.List(s)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user