github.com/wangyougui/gf/v2@v2.6.5/container/gmap/gmap_z_bench_maps_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 "testing" 13 14 "github.com/wangyougui/gf/v2/container/gmap" 15 "github.com/wangyougui/gf/v2/util/gutil" 16 ) 17 18 var hashMap = gmap.New(true) 19 20 var listMap = gmap.NewListMap(true) 21 22 var treeMap = gmap.NewTreeMap(gutil.ComparatorInt, true) 23 24 func Benchmark_HashMap_Set(b *testing.B) { 25 b.RunParallel(func(pb *testing.PB) { 26 i := 0 27 for pb.Next() { 28 hashMap.Set(i, i) 29 i++ 30 } 31 }) 32 } 33 34 func Benchmark_ListMap_Set(b *testing.B) { 35 b.RunParallel(func(pb *testing.PB) { 36 i := 0 37 for pb.Next() { 38 listMap.Set(i, i) 39 i++ 40 } 41 }) 42 } 43 44 func Benchmark_TreeMap_Set(b *testing.B) { 45 b.RunParallel(func(pb *testing.PB) { 46 i := 0 47 for pb.Next() { 48 treeMap.Set(i, i) 49 i++ 50 } 51 }) 52 } 53 54 func Benchmark_HashMap_Get(b *testing.B) { 55 b.RunParallel(func(pb *testing.PB) { 56 i := 0 57 for pb.Next() { 58 hashMap.Get(i) 59 i++ 60 } 61 }) 62 } 63 64 func Benchmark_ListMap_Get(b *testing.B) { 65 b.RunParallel(func(pb *testing.PB) { 66 i := 0 67 for pb.Next() { 68 listMap.Get(i) 69 i++ 70 } 71 }) 72 } 73 74 func Benchmark_TreeMap_Get(b *testing.B) { 75 b.RunParallel(func(pb *testing.PB) { 76 i := 0 77 for pb.Next() { 78 treeMap.Get(i) 79 i++ 80 } 81 }) 82 }