Skip to content

Commit d87cc0c

Browse files
committed
test names reflect new API
1 parent a1a3e50 commit d87cc0c

File tree

3 files changed

+77
-95
lines changed

3 files changed

+77
-95
lines changed

bench_test.go

+10-28
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var intMap = map[int]string{
2424
1_000_000: "1_000_000",
2525
}
2626

27-
func BenchmarkLookupIP(b *testing.B) {
27+
func BenchmarkLookup(b *testing.B) {
2828
for k := 1; k <= 1_000_000; k *= 10 {
2929
rt := new(cidrtree.Table)
3030
cidrs := shuffleFullTable(k)
@@ -44,7 +44,7 @@ func BenchmarkLookupIP(b *testing.B) {
4444
}
4545
}
4646

47-
func BenchmarkLookupCIDR(b *testing.B) {
47+
func BenchmarkLookupPrefix(b *testing.B) {
4848
for k := 1; k <= 1_000_000; k *= 10 {
4949
rt := new(cidrtree.Table)
5050
cidrs := shuffleFullTable(k)
@@ -63,7 +63,7 @@ func BenchmarkLookupCIDR(b *testing.B) {
6363
}
6464
}
6565

66-
func BenchmarkNew(b *testing.B) {
66+
func BenchmarkInsertImmutable(b *testing.B) {
6767
for k := 1; k <= 1_000_000; k *= 10 {
6868
cidrs := shuffleFullTable(k)
6969
name := fmt.Sprintf("%10s", intMap[k])
@@ -82,7 +82,7 @@ func BenchmarkClone(b *testing.B) {
8282
for k := 1; k <= 1_000_000; k *= 10 {
8383
rt := new(cidrtree.Table)
8484
for _, cidr := range shuffleFullTable(k) {
85-
rt = rt.InsertImmutable(cidr, nil)
85+
rt.Insert(cidr, nil)
8686
}
8787
name := fmt.Sprintf("%10s", intMap[k])
8888
b.ResetTimer()
@@ -99,25 +99,7 @@ func BenchmarkInsert(b *testing.B) {
9999
rt := new(cidrtree.Table)
100100
cidrs := shuffleFullTable(k)
101101
for _, cidr := range cidrs {
102-
rt = rt.InsertImmutable(cidr, 0)
103-
}
104-
probe := routes[mrand.Intn(len(routes))]
105-
name := fmt.Sprintf("Into%10s", intMap[k])
106-
b.ResetTimer()
107-
b.Run(name, func(b *testing.B) {
108-
for n := 0; n < b.N; n++ {
109-
_ = rt.InsertImmutable(probe.cidr, 0)
110-
}
111-
})
112-
}
113-
}
114-
115-
func BenchmarkInsertMutable(b *testing.B) {
116-
for k := 1; k <= 1_000_000; k *= 10 {
117-
rt := new(cidrtree.Table)
118-
cidrs := shuffleFullTable(k)
119-
for _, cidr := range cidrs {
120-
rt = rt.InsertImmutable(cidr, 0)
102+
rt.Insert(cidr, 0)
121103
}
122104
probe := routes[mrand.Intn(len(routes))]
123105
name := fmt.Sprintf("Into%10s", intMap[k])
@@ -135,34 +117,34 @@ func BenchmarkDelete(b *testing.B) {
135117
rt := new(cidrtree.Table)
136118
cidrs := shuffleFullTable(k)
137119
for _, cidr := range cidrs {
138-
rt = rt.InsertImmutable(cidr, nil)
120+
rt.Insert(cidr, nil)
139121
}
140122
probe := routes[mrand.Intn(len(routes))]
141123
name := fmt.Sprintf("From%10s", intMap[k])
142124

143125
b.ResetTimer()
144126
b.Run(name, func(b *testing.B) {
145127
for n := 0; n < b.N; n++ {
146-
_, _ = rt.DeleteImmutable(probe.cidr)
128+
_ = rt.Delete(probe.cidr)
147129
}
148130
})
149131
}
150132
}
151133

152-
func BenchmarkDeleteMutable(b *testing.B) {
134+
func BenchmarkDeleteImmutable(b *testing.B) {
153135
for k := 1; k <= 1_000_000; k *= 10 {
154136
rt := new(cidrtree.Table)
155137
cidrs := shuffleFullTable(k)
156138
for _, cidr := range cidrs {
157-
rt = rt.InsertImmutable(cidr, nil)
139+
rt.Insert(cidr, nil)
158140
}
159141
probe := routes[mrand.Intn(len(routes))]
160142
name := fmt.Sprintf("From%10s", intMap[k])
161143

162144
b.ResetTimer()
163145
b.Run(name, func(b *testing.B) {
164146
for n := 0; n < b.N; n++ {
165-
_ = rt.Delete(probe.cidr)
147+
_, _ = rt.DeleteImmutable(probe.cidr)
166148
}
167149
})
168150
}

example_test.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ import (
88
"github.com/gaissmai/cidrtree"
99
)
1010

11-
func a(s string) netip.Addr {
11+
func addr(s string) netip.Addr {
1212
return netip.MustParseAddr(s)
1313
}
1414

15-
func p(s string) netip.Prefix {
15+
func prfx(s string) netip.Prefix {
1616
return netip.MustParsePrefix(s)
1717
}
1818

1919
var input = []netip.Prefix{
20-
p("fe80::/10"),
21-
p("172.16.0.0/12"),
22-
p("10.0.0.0/24"),
23-
p("::1/128"),
24-
p("192.168.0.0/16"),
25-
p("10.0.0.0/8"),
26-
p("::/0"),
27-
p("10.0.1.0/24"),
28-
p("169.254.0.0/16"),
29-
p("2000::/3"),
30-
p("2001:db8::/32"),
31-
p("127.0.0.0/8"),
32-
p("127.0.0.1/32"),
33-
p("192.168.1.0/24"),
20+
prfx("fe80::/10"),
21+
prfx("172.16.0.0/12"),
22+
prfx("10.0.0.0/24"),
23+
prfx("::1/128"),
24+
prfx("192.168.0.0/16"),
25+
prfx("10.0.0.0/8"),
26+
prfx("::/0"),
27+
prfx("10.0.1.0/24"),
28+
prfx("169.254.0.0/16"),
29+
prfx("2000::/3"),
30+
prfx("2001:db8::/32"),
31+
prfx("127.0.0.0/8"),
32+
prfx("127.0.0.1/32"),
33+
prfx("192.168.1.0/24"),
3434
}
3535

3636
func ExampleTable_Lookup() {
@@ -42,15 +42,15 @@ func ExampleTable_Lookup() {
4242

4343
fmt.Println()
4444

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

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

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

0 commit comments

Comments
 (0)