github.com/wangyougui/gf/v2@v2.6.5/container/gmap/gmap_z_bench_unsafe_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with gm file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 // go test *.go -bench=".*" -benchmem 8 9 package gmap_test 10 11 import ( 12 "strconv" 13 "testing" 14 15 "github.com/wangyougui/gf/v2/container/gmap" 16 ) 17 18 var anyAnyMapUnsafe = gmap.New() 19 20 var intIntMapUnsafe = gmap.NewIntIntMap() 21 22 var intAnyMapUnsafe = gmap.NewIntAnyMap() 23 24 var intStrMapUnsafe = gmap.NewIntStrMap() 25 26 var strIntMapUnsafe = gmap.NewStrIntMap() 27 28 var strAnyMapUnsafe = gmap.NewStrAnyMap() 29 30 var strStrMapUnsafe = gmap.NewStrStrMap() 31 32 // Writing benchmarks. 33 34 func Benchmark_Unsafe_IntIntMap_Set(b *testing.B) { 35 for i := 0; i < b.N; i++ { 36 intIntMapUnsafe.Set(i, i) 37 } 38 } 39 40 func Benchmark_Unsafe_IntAnyMap_Set(b *testing.B) { 41 for i := 0; i < b.N; i++ { 42 intAnyMapUnsafe.Set(i, i) 43 } 44 } 45 46 func Benchmark_Unsafe_IntStrMap_Set(b *testing.B) { 47 for i := 0; i < b.N; i++ { 48 intStrMapUnsafe.Set(i, strconv.Itoa(i)) 49 } 50 } 51 52 func Benchmark_Unsafe_AnyAnyMap_Set(b *testing.B) { 53 for i := 0; i < b.N; i++ { 54 anyAnyMapUnsafe.Set(i, i) 55 } 56 } 57 58 func Benchmark_Unsafe_StrIntMap_Set(b *testing.B) { 59 for i := 0; i < b.N; i++ { 60 strIntMapUnsafe.Set(strconv.Itoa(i), i) 61 } 62 } 63 64 func Benchmark_Unsafe_StrAnyMap_Set(b *testing.B) { 65 for i := 0; i < b.N; i++ { 66 strAnyMapUnsafe.Set(strconv.Itoa(i), i) 67 } 68 } 69 70 func Benchmark_Unsafe_StrStrMap_Set(b *testing.B) { 71 for i := 0; i < b.N; i++ { 72 strStrMapUnsafe.Set(strconv.Itoa(i), strconv.Itoa(i)) 73 } 74 } 75 76 // Reading benchmarks. 77 78 func Benchmark_Unsafe_IntIntMap_Get(b *testing.B) { 79 for i := 0; i < b.N; i++ { 80 intIntMapUnsafe.Get(i) 81 } 82 } 83 84 func Benchmark_Unsafe_IntAnyMap_Get(b *testing.B) { 85 for i := 0; i < b.N; i++ { 86 intAnyMapUnsafe.Get(i) 87 } 88 } 89 90 func Benchmark_Unsafe_IntStrMap_Get(b *testing.B) { 91 for i := 0; i < b.N; i++ { 92 intStrMapUnsafe.Get(i) 93 } 94 } 95 96 func Benchmark_Unsafe_AnyAnyMap_Get(b *testing.B) { 97 for i := 0; i < b.N; i++ { 98 anyAnyMapUnsafe.Get(i) 99 } 100 } 101 102 func Benchmark_Unsafe_StrIntMap_Get(b *testing.B) { 103 for i := 0; i < b.N; i++ { 104 strIntMapUnsafe.Get(strconv.Itoa(i)) 105 } 106 } 107 108 func Benchmark_Unsafe_StrAnyMap_Get(b *testing.B) { 109 for i := 0; i < b.N; i++ { 110 strAnyMapUnsafe.Get(strconv.Itoa(i)) 111 } 112 } 113 114 func Benchmark_Unsafe_StrStrMap_Get(b *testing.B) { 115 for i := 0; i < b.N; i++ { 116 strStrMapUnsafe.Get(strconv.Itoa(i)) 117 } 118 }