github.com/songzhibin97/gkit@v1.2.13/structure/skipmap/bench_test.go (about) 1 package skipmap 2 3 import ( 4 "testing" 5 6 "github.com/songzhibin97/gkit/sys/fastrand" 7 ) 8 9 func BenchmarkLoadOrStoreExist(b *testing.B) { 10 m := NewInt() 11 m.Store(1, 1) 12 b.ResetTimer() 13 b.RunParallel(func(p *testing.PB) { 14 for p.Next() { 15 m.LoadOrStore(1, 1) 16 } 17 }) 18 } 19 20 func BenchmarkLoadOrStoreLazyExist(b *testing.B) { 21 m := NewInt() 22 m.Store(1, 1) 23 b.ResetTimer() 24 b.RunParallel(func(p *testing.PB) { 25 for p.Next() { 26 m.LoadOrStoreLazy(1, func() interface{} { return 1 }) 27 } 28 }) 29 } 30 31 func BenchmarkLoadOrStoreExistSingle(b *testing.B) { 32 m := NewInt() 33 m.Store(1, 1) 34 b.ResetTimer() 35 for i := 0; i < b.N; i++ { 36 m.LoadOrStore(1, 1) 37 } 38 } 39 40 func BenchmarkLoadOrStoreLazyExistSingle(b *testing.B) { 41 m := NewInt() 42 m.Store(1, 1) 43 b.ResetTimer() 44 for i := 0; i < b.N; i++ { 45 m.LoadOrStoreLazy(1, func() interface{} { return 1 }) 46 } 47 } 48 49 func BenchmarkLoadOrStoreRandom(b *testing.B) { 50 m := NewInt() 51 b.ResetTimer() 52 b.RunParallel(func(p *testing.PB) { 53 for p.Next() { 54 m.LoadOrStore(fastrand.Int(), 1) 55 } 56 }) 57 } 58 59 func BenchmarkLoadOrStoreLazyRandom(b *testing.B) { 60 m := NewInt() 61 b.ResetTimer() 62 b.RunParallel(func(p *testing.PB) { 63 for p.Next() { 64 m.LoadOrStoreLazy(fastrand.Int(), func() interface{} { return 1 }) 65 } 66 }) 67 } 68 69 func BenchmarkLoadOrStoreRandomSingle(b *testing.B) { 70 m := NewInt() 71 b.ResetTimer() 72 for i := 0; i < b.N; i++ { 73 m.LoadOrStore(fastrand.Int(), 1) 74 } 75 } 76 77 func BenchmarkLoadOrStoreLazyRandomSingle(b *testing.B) { 78 m := NewInt() 79 b.ResetTimer() 80 for i := 0; i < b.N; i++ { 81 m.LoadOrStoreLazy(fastrand.Int(), func() interface{} { return 1 }) 82 } 83 }