Skip to content

Commit

Permalink
test names reflect new API
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Jan 5, 2024
1 parent a1a3e50 commit d87cc0c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 95 deletions.
38 changes: 10 additions & 28 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var intMap = map[int]string{
1_000_000: "1_000_000",
}

func BenchmarkLookupIP(b *testing.B) {
func BenchmarkLookup(b *testing.B) {
for k := 1; k <= 1_000_000; k *= 10 {
rt := new(cidrtree.Table)
cidrs := shuffleFullTable(k)
Expand All @@ -44,7 +44,7 @@ func BenchmarkLookupIP(b *testing.B) {
}
}

func BenchmarkLookupCIDR(b *testing.B) {
func BenchmarkLookupPrefix(b *testing.B) {
for k := 1; k <= 1_000_000; k *= 10 {
rt := new(cidrtree.Table)
cidrs := shuffleFullTable(k)
Expand All @@ -63,7 +63,7 @@ func BenchmarkLookupCIDR(b *testing.B) {
}
}

func BenchmarkNew(b *testing.B) {
func BenchmarkInsertImmutable(b *testing.B) {
for k := 1; k <= 1_000_000; k *= 10 {
cidrs := shuffleFullTable(k)
name := fmt.Sprintf("%10s", intMap[k])
Expand All @@ -82,7 +82,7 @@ func BenchmarkClone(b *testing.B) {
for k := 1; k <= 1_000_000; k *= 10 {
rt := new(cidrtree.Table)
for _, cidr := range shuffleFullTable(k) {
rt = rt.InsertImmutable(cidr, nil)
rt.Insert(cidr, nil)
}
name := fmt.Sprintf("%10s", intMap[k])
b.ResetTimer()
Expand All @@ -99,25 +99,7 @@ func BenchmarkInsert(b *testing.B) {
rt := new(cidrtree.Table)
cidrs := shuffleFullTable(k)
for _, cidr := range cidrs {
rt = rt.InsertImmutable(cidr, 0)
}
probe := routes[mrand.Intn(len(routes))]
name := fmt.Sprintf("Into%10s", intMap[k])
b.ResetTimer()
b.Run(name, func(b *testing.B) {
for n := 0; n < b.N; n++ {
_ = rt.InsertImmutable(probe.cidr, 0)
}
})
}
}

func BenchmarkInsertMutable(b *testing.B) {
for k := 1; k <= 1_000_000; k *= 10 {
rt := new(cidrtree.Table)
cidrs := shuffleFullTable(k)
for _, cidr := range cidrs {
rt = rt.InsertImmutable(cidr, 0)
rt.Insert(cidr, 0)
}
probe := routes[mrand.Intn(len(routes))]
name := fmt.Sprintf("Into%10s", intMap[k])
Expand All @@ -135,34 +117,34 @@ func BenchmarkDelete(b *testing.B) {
rt := new(cidrtree.Table)
cidrs := shuffleFullTable(k)
for _, cidr := range cidrs {
rt = rt.InsertImmutable(cidr, nil)
rt.Insert(cidr, nil)
}
probe := routes[mrand.Intn(len(routes))]
name := fmt.Sprintf("From%10s", intMap[k])

b.ResetTimer()
b.Run(name, func(b *testing.B) {
for n := 0; n < b.N; n++ {
_, _ = rt.DeleteImmutable(probe.cidr)
_ = rt.Delete(probe.cidr)
}
})
}
}

func BenchmarkDeleteMutable(b *testing.B) {
func BenchmarkDeleteImmutable(b *testing.B) {
for k := 1; k <= 1_000_000; k *= 10 {
rt := new(cidrtree.Table)
cidrs := shuffleFullTable(k)
for _, cidr := range cidrs {
rt = rt.InsertImmutable(cidr, nil)
rt.Insert(cidr, nil)
}
probe := routes[mrand.Intn(len(routes))]
name := fmt.Sprintf("From%10s", intMap[k])

b.ResetTimer()
b.Run(name, func(b *testing.B) {
for n := 0; n < b.N; n++ {
_ = rt.Delete(probe.cidr)
_, _ = rt.DeleteImmutable(probe.cidr)
}
})
}
Expand Down
38 changes: 19 additions & 19 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import (
"github.com/gaissmai/cidrtree"
)

func a(s string) netip.Addr {
func addr(s string) netip.Addr {
return netip.MustParseAddr(s)
}

func p(s string) netip.Prefix {
func prfx(s string) netip.Prefix {
return netip.MustParsePrefix(s)
}

var input = []netip.Prefix{
p("fe80::/10"),
p("172.16.0.0/12"),
p("10.0.0.0/24"),
p("::1/128"),
p("192.168.0.0/16"),
p("10.0.0.0/8"),
p("::/0"),
p("10.0.1.0/24"),
p("169.254.0.0/16"),
p("2000::/3"),
p("2001:db8::/32"),
p("127.0.0.0/8"),
p("127.0.0.1/32"),
p("192.168.1.0/24"),
prfx("fe80::/10"),
prfx("172.16.0.0/12"),
prfx("10.0.0.0/24"),
prfx("::1/128"),
prfx("192.168.0.0/16"),
prfx("10.0.0.0/8"),
prfx("::/0"),
prfx("10.0.1.0/24"),
prfx("169.254.0.0/16"),
prfx("2000::/3"),
prfx("2001:db8::/32"),
prfx("127.0.0.0/8"),
prfx("127.0.0.1/32"),
prfx("192.168.1.0/24"),
}

func ExampleTable_Lookup() {
Expand All @@ -42,15 +42,15 @@ func ExampleTable_Lookup() {

fmt.Println()

ip := a("42.0.0.0")
ip := addr("42.0.0.0")
lpm, value, ok := rtbl.Lookup(ip)
fmt.Printf("Lookup: %-20v lpm: %-15v value: %v, ok: %v\n", ip, lpm, value, ok)

ip = a("10.0.1.17")
ip = addr("10.0.1.17")
lpm, value, ok = rtbl.Lookup(ip)
fmt.Printf("Lookup: %-20v lpm: %-15v value: %v, ok: %v\n", ip, lpm, value, ok)

ip = a("2001:7c0:3100:1::111")
ip = addr("2001:7c0:3100:1::111")
lpm, value, ok = rtbl.Lookup(ip)
fmt.Printf("Lookup: %-20v lpm: %-15v value: %v, ok: %v\n", ip, lpm, value, ok)

Expand Down
Loading

0 comments on commit d87cc0c

Please sign in to comment.