MCPcopy
hub / github.com/kopia/kopia / benchmarkSyncMap

Function benchmarkSyncMap

internal/bigmap/bigmap_internal_test.go:215–249  ·  view source on GitHub ↗

nolint:thelper

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

Source from the content-addressed store, hash-verified

213
214//nolint:thelper
215func benchmarkSyncMap(b *testing.B, someVal []byte) {
216 var m sync.Map
217
218 var (
219 h = sha256.New()
220 num [8]byte
221 keyBuf [sha256.Size]byte
222 )
223
224 b.ResetTimer()
225
226 for i := range b.N {
227 // generate key=sha256(i) without allocations.
228 h.Reset()
229 binary.LittleEndian.PutUint64(num[:], uint64(i))
230 h.Write(num[:])
231 key := h.Sum(keyBuf[:0])
232
233 m.Store(string(key), append([]byte{}, someVal...))
234 }
235
236 for range 4 {
237 for i := range b.N {
238 // generate key=sha256(i) without allocations.
239 h.Reset()
240 binary.LittleEndian.PutUint64(num[:], uint64(i))
241 h.Write(num[:])
242 key := h.Sum(keyBuf[:0])
243
244 val, ok := m.Load(string(key))
245 require.True(b, ok)
246 require.Equal(b, someVal, val)
247 }
248 }
249}
250
251func TestErrors(t *testing.T) {
252 ctx := testlogging.Context(t)

Callers 2

BenchmarkSyncMap_NoValueFunction · 0.85

Calls 5

EqualMethod · 0.80
ResetMethod · 0.65
StoreMethod · 0.65
LoadMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected