Skip to content

Commit c114899

Browse files
committed
Add some benchmarks
1 parent 1077c50 commit c114899

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

‎radix_test.go‎

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func TestRadix(t *testing.T) {
2929
}
3030

3131
r.Walk(func(k string, v any) bool {
32-
println(k)
3332
return false
3433
})
3534

@@ -88,7 +87,6 @@ func TestRoot(t *testing.T) {
8887
}
8988

9089
func TestDelete(t *testing.T) {
91-
9290
r := New()
9391

9492
s := []string{"", "A", "AB"}
@@ -406,3 +404,71 @@ func BenchmarkInsert(b *testing.B) {
406404
}
407405
}
408406
}
407+
408+
func BenchmarkRadix(b *testing.B) {
409+
r := New()
410+
411+
type v struct {
412+
s string
413+
}
414+
for i := range 100 {
415+
for j := range 100 {
416+
r.Insert(fmt.Sprintf("init%d/%d", i, j), &v{s: "hello"})
417+
}
418+
}
419+
420+
b.ResetTimer()
421+
422+
b.Run("Walk", func(b *testing.B) {
423+
for b.Loop() {
424+
r.Walk(func(s string, v any) bool {
425+
return false
426+
})
427+
}
428+
})
429+
430+
b.Run("WalkPrefix", func(b *testing.B) {
431+
for b.Loop() {
432+
r.WalkPrefix("init50", func(s string, v any) bool {
433+
return false
434+
})
435+
}
436+
})
437+
438+
b.Run("WalkPath", func(b *testing.B) {
439+
for b.Loop() {
440+
r.WalkPath("init50/50", func(s string, v any) bool {
441+
return false
442+
})
443+
}
444+
})
445+
446+
b.Run("Walk", func(b *testing.B) {
447+
for b.Loop() {
448+
r.Walk(func(s string, v any) bool {
449+
return false
450+
})
451+
}
452+
})
453+
454+
b.Run("Get", func(b *testing.B) {
455+
for b.Loop() {
456+
v, ok := r.Get("init50/50")
457+
_ = v
458+
if !ok {
459+
b.Fatal("bad")
460+
}
461+
}
462+
})
463+
464+
b.Run("LongestPrefix", func(b *testing.B) {
465+
for b.Loop() {
466+
s, v, ok := r.LongestPrefix("init50/50")
467+
_ = s
468+
_ = v
469+
if !ok {
470+
b.Fatal("bad")
471+
}
472+
}
473+
})
474+
}

0 commit comments

Comments
 (0)