MCPcopy
hub / github.com/kopia/kopia / benchmarkMap

Function benchmarkMap

internal/bigmap/bigmap_map_test.go:94–130  ·  view source on GitHub ↗

nolint:thelper

(b *testing.B, m *bigmap.Map, someVal []byte)

Source from the content-addressed store, hash-verified

92
93//nolint:thelper
94func benchmarkMap(b *testing.B, m *bigmap.Map, someVal []byte) {
95 ctx := testlogging.Context(b)
96
97 b.ResetTimer()
98
99 var (
100 h = sha256.New()
101 num [8]byte
102 keyBuf [sha256.Size]byte
103 )
104
105 for i := range b.N {
106 // generate key=sha256(i) without allocations.
107 h.Reset()
108 binary.LittleEndian.PutUint64(num[:], uint64(i))
109 h.Write(num[:])
110 key := h.Sum(keyBuf[:0])
111
112 m.PutIfAbsent(ctx, key, someVal)
113 }
114
115 valBuf := make([]byte, 10)
116
117 for range 4 {
118 for i := range b.N {
119 // generate key=sha256(i) without allocations.
120 h.Reset()
121 binary.LittleEndian.PutUint64(num[:], uint64(i))
122 h.Write(num[:])
123 key := h.Sum(keyBuf[:0])
124
125 _, ok, err := m.Get(ctx, valBuf[:0], key)
126 require.NoError(b, err)
127 require.True(b, ok)
128 }
129 }
130}

Callers 2

BenchmarkMap_NoValueFunction · 0.85
BenchmarkMap_WithValueFunction · 0.85

Calls 5

ContextFunction · 0.92
ResetMethod · 0.65
GetMethod · 0.65
WriteMethod · 0.45
PutIfAbsentMethod · 0.45

Tested by

no test coverage detected