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