github.com/saintwish/kv@v1.0.4/main_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 "sync" 6 7 "github.com/saintwish/kv/ccmap" 8 "github.com/saintwish/kv/kv1" 9 "github.com/saintwish/kv/kvmap" 10 ) 11 12 func Benchmark_CCMap(b *testing.B) { 13 m := ccmap.New[int, blank]() 14 s := blank{test: 1337, test2: blank2{}} 15 16 b.ResetTimer() 17 for i := 0; i < b.N; i++ { 18 for e := 1; e <= maxEntries; e++ { 19 m.Set(e, s) 20 } 21 22 for e := 1; e <= maxEntries; e++ { 23 m.Get(e) 24 } 25 } 26 } 27 28 func Benchmark_CCMap_Parallel(b *testing.B) { 29 m := ccmap.New[int, blank]() 30 s := blank{test: 1337, test2: blank2{}} 31 32 b.ResetTimer() 33 b.RunParallel(func(pb *testing.PB) { 34 for pb.Next() { 35 for e := 1; e <= maxEntries; e++ { 36 m.Set(e, s) 37 } 38 39 for e := 1; e <= maxEntries; e++ { 40 m.Get(e) 41 } 42 } 43 }) 44 } 45 46 func Benchmark_KV1(b *testing.B) { 47 m := kv1.New[int, blank](0, 2048, 8) 48 s := blank{test: 1337, test2: blank2{}} 49 50 b.ResetTimer() 51 for i := 0; i < b.N; i++ { 52 for e := 1; e <= maxEntries; e++ { 53 m.Set(e, s) 54 } 55 56 for e := 1; e <= maxEntries; e++ { 57 m.Get(e) 58 } 59 } 60 } 61 62 func Benchmark_KV1_Parallel(b *testing.B) { 63 m := kv1.New[int, blank](0, 2048, 8) 64 s := blank{test: 1337, test2: blank2{}} 65 66 b.ResetTimer() 67 b.RunParallel(func(pb *testing.PB) { 68 for pb.Next() { 69 for e := 1; e <= maxEntries; e++ { 70 m.Set(e, s) 71 } 72 73 for e := 1; e <= maxEntries; e++ { 74 m.Get(e) 75 } 76 } 77 }) 78 } 79 80 func Benchmark_KVMap(b *testing.B) { 81 m := kvmap.New[int, blank](8) 82 s := blank{test: 1337, test2: blank2{}} 83 84 b.ResetTimer() 85 for i := 0; i < b.N; i++ { 86 for e := 1; e <= maxEntries; e++ { 87 m.Set(e, s) 88 } 89 90 for e := 1; e <= maxEntries; e++ { 91 m.Get(e) 92 } 93 } 94 } 95 96 func Benchmark_KVMap_Parallel(b *testing.B) { 97 m := kvmap.New[int, blank](8) 98 s := blank{test: 1337, test2: blank2{}} 99 100 b.ResetTimer() 101 b.RunParallel(func(pb *testing.PB) { 102 for pb.Next() { 103 for e := 1; e <= maxEntries; e++ { 104 m.Set(e, s) 105 } 106 107 for e := 1; e <= maxEntries; e++ { 108 m.Get(e) 109 } 110 } 111 }) 112 } 113 114 func Benchmark_SyncMap(b *testing.B) { 115 var m sync.Map 116 s := blank{test: 1337, test2: blank2{}} 117 118 b.ResetTimer() 119 for i := 0; i < b.N; i++ { 120 for e := 1; e <= maxEntries; e++ { 121 m.Store(e, s) 122 } 123 124 for e := 1; e <= maxEntries; e++ { 125 m.Load(e) 126 } 127 } 128 } 129 130 func Benchmark_SyncMap_Parallel(b *testing.B) { 131 var m sync.Map 132 s := blank{test: 1337, test2: blank2{}} 133 134 b.ResetTimer() 135 b.RunParallel(func(pb *testing.PB) { 136 for pb.Next() { 137 for e := 1; e <= maxEntries; e++ { 138 m.Store(e, s) 139 } 140 141 for e := 1; e <= maxEntries; e++ { 142 m.Load(e) 143 } 144 } 145 }) 146 }