2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2019-05-13 22:37:05 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with gm file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
// go test *.go -bench=".*" -benchmem
|
|
|
|
|
|
|
|
package gmap_test
|
|
|
|
|
|
|
|
import (
|
2019-07-16 20:30:10 +08:00
|
|
|
"testing"
|
|
|
|
|
2019-07-29 21:01:19 +08:00
|
|
|
"github.com/gogf/gf/container/gmap"
|
|
|
|
"github.com/gogf/gf/util/gutil"
|
2019-05-13 22:37:05 +08:00
|
|
|
)
|
|
|
|
|
2019-08-26 23:35:44 +08:00
|
|
|
var hashMap = gmap.New(true)
|
|
|
|
var listMap = gmap.NewListMap(true)
|
|
|
|
var treeMap = gmap.NewTreeMap(gutil.ComparatorInt, true)
|
2019-05-13 22:37:05 +08:00
|
|
|
|
|
|
|
func Benchmark_HashMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
hashMap.Set(i, i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2019-05-13 22:37:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_ListMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
listMap.Set(i, i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2019-05-13 22:37:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_TreeMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
treeMap.Set(i, i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2019-05-13 22:37:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_HashMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
hashMap.Get(i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2019-05-13 22:37:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_ListMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
listMap.Get(i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2019-05-13 22:37:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_TreeMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
treeMap.Get(i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2019-05-13 22:37:05 +08:00
|
|
|
}
|