expand the fill benchmark with subtest for different prefix lengths
This commit is contained in:
parent
4d8620ebd7
commit
630e845504
|
@ -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 {
|
||||
if alloc := root.Alloc(32); alloc == nil {
|
||||
break
|
||||
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 {
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user