expand the fill benchmark with subtest for different prefix lengths

This commit is contained in:
Johannes Kimmel 2023-11-13 20:19:06 +01:00
parent 4d8620ebd7
commit 630e845504
1 changed files with 17 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package ipalloc
import (
"fmt"
"log"
"net/netip"
"testing"
@ -223,11 +224,23 @@ func TestAllocDealloc(t *testing.T) {
expectAlloc(t, root, 32, "0.0.0.1/32")
}
func BenchmarkFill(b *testing.B) {
root := &tree{prefix: netip.MustParsePrefix("0.0.0.0/16")}
for {
func benchRunN(b *testing.B, bits int) {
root := &tree{
prefix: netip.PrefixFrom(netip.MustParseAddr("0.0.0.0"), bits),
}
for i := 0; i < b.N; i++ {
if alloc := root.Alloc(32); alloc == nil {
break
root = &tree{
prefix: netip.PrefixFrom(netip.MustParseAddr("0.0.0.0"), bits),
}
}
}
}
func BenchmarkFill(b *testing.B) {
for bits := 24; bits >= 0; bits -= 8 {
b.Run(fmt.Sprintf("BenchmarkFill-%2d", bits), func(b *testing.B) {
benchRunN(b, bits)
})
}
}