@@ -3,6 +3,7 @@ package hamt
3
3
import (
4
4
"context"
5
5
"encoding/hex"
6
+ "fmt"
6
7
"math/rand"
7
8
"runtime"
8
9
"testing"
@@ -47,6 +48,40 @@ func BenchmarkSerializeNode(b *testing.B) {
47
48
}
48
49
}
49
50
51
+ type benchSetCase struct {
52
+ count int
53
+ bitwidth int
54
+ }
55
+
56
+ func BenchmarkSet (b * testing.B ) {
57
+ kCounts := []int {1 , 10 , 100 }
58
+ bitwidths := []int {5 , 8 }
59
+
60
+ var table []benchSetCase
61
+ for _ , c := range kCounts {
62
+
63
+ for _ , bw := range bitwidths {
64
+ table = append (table , benchSetCase {count : c * 1000 , bitwidth : bw })
65
+ }
66
+
67
+ }
68
+ r := rander {rand .New (rand .NewSource (int64 (42 )))}
69
+ for _ , t := range table {
70
+ b .Run (fmt .Sprintf ("%d/%d" , t .count , t .bitwidth ), func (b * testing.B ) {
71
+ ctx := context .Background ()
72
+ n := NewNode (NewCborStore (), UseTreeBitWidth (t .bitwidth ))
73
+ b .ResetTimer ()
74
+ for i := 0 ; i < b .N ; i ++ {
75
+ for j := 0 ; j < t .count ; j ++ {
76
+ if err := n .Set (ctx , r .randString (), r .randValue ()); err != nil {
77
+ b .Fatal (err )
78
+ }
79
+ }
80
+ }
81
+ })
82
+ }
83
+ }
84
+
50
85
func BenchmarkFind (b * testing.B ) {
51
86
b .Run ("find-10k" , doBenchmarkEntriesCount (10000 , 8 ))
52
87
b .Run ("find-100k" , doBenchmarkEntriesCount (100000 , 8 ))
0 commit comments