File size: 1,353 Bytes
13c2bf6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sync_test
import (
isync "internal/sync"
"testing"
)
func BenchmarkHashTrieMapLoadSmall(b *testing.B) {
benchmarkHashTrieMapLoad(b, testDataSmall[:])
}
func BenchmarkHashTrieMapLoad(b *testing.B) {
benchmarkHashTrieMapLoad(b, testData[:])
}
func BenchmarkHashTrieMapLoadLarge(b *testing.B) {
benchmarkHashTrieMapLoad(b, testDataLarge[:])
}
func benchmarkHashTrieMapLoad(b *testing.B, data []string) {
b.ReportAllocs()
var m isync.HashTrieMap[string, int]
for i := range data {
m.LoadOrStore(data[i], i)
}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
_, _ = m.Load(data[i])
i++
if i >= len(data) {
i = 0
}
}
})
}
func BenchmarkHashTrieMapLoadOrStore(b *testing.B) {
benchmarkHashTrieMapLoadOrStore(b, testData[:])
}
func BenchmarkHashTrieMapLoadOrStoreLarge(b *testing.B) {
benchmarkHashTrieMapLoadOrStore(b, testDataLarge[:])
}
func benchmarkHashTrieMapLoadOrStore(b *testing.B, data []string) {
b.ReportAllocs()
var m isync.HashTrieMap[string, int]
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
_, _ = m.LoadOrStore(data[i], i)
i++
if i >= len(data) {
i = 0
}
}
})
}
|