github.com/zhongdalu/gf@v1.0.0/g/container/gmap/gmap_z_bench_maps_test.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). 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/zhongdalu/gf. 6 7 // go test *.go -bench=".*" -benchmem 8 9 package gmap_test 10 11 import ( 12 "testing" 13 14 "github.com/zhongdalu/gf/g/container/gmap" 15 "github.com/zhongdalu/gf/g/util/gutil" 16 ) 17 18 var hashMap = gmap.New() 19 var listMap = gmap.NewListMap() 20 var treeMap = gmap.NewTreeMap(gutil.ComparatorInt) 21 22 func Benchmark_HashMap_Set(b *testing.B) { 23 b.RunParallel(func(pb *testing.PB) { 24 i := 0 25 for pb.Next() { 26 hashMap.Set(i, i) 27 i++ 28 } 29 }) 30 } 31 32 func Benchmark_ListMap_Set(b *testing.B) { 33 b.RunParallel(func(pb *testing.PB) { 34 i := 0 35 for pb.Next() { 36 listMap.Set(i, i) 37 i++ 38 } 39 }) 40 } 41 42 func Benchmark_TreeMap_Set(b *testing.B) { 43 b.RunParallel(func(pb *testing.PB) { 44 i := 0 45 for pb.Next() { 46 treeMap.Set(i, i) 47 i++ 48 } 49 }) 50 } 51 52 func Benchmark_HashMap_Get(b *testing.B) { 53 b.RunParallel(func(pb *testing.PB) { 54 i := 0 55 for pb.Next() { 56 hashMap.Get(i) 57 i++ 58 } 59 }) 60 } 61 62 func Benchmark_ListMap_Get(b *testing.B) { 63 b.RunParallel(func(pb *testing.PB) { 64 i := 0 65 for pb.Next() { 66 listMap.Get(i) 67 i++ 68 } 69 }) 70 } 71 72 func Benchmark_TreeMap_Get(b *testing.B) { 73 b.RunParallel(func(pb *testing.PB) { 74 i := 0 75 for pb.Next() { 76 treeMap.Get(i) 77 i++ 78 } 79 }) 80 }