diff --git a/ipalloc/ipalloc_test.go b/ipalloc/ipalloc_test.go index e49fddb..0508923 100644 --- a/ipalloc/ipalloc_test.go +++ b/ipalloc/ipalloc_test.go @@ -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) + }) + } }