2019-02-02 16:18:25 +08:00
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
2018-02-28 14:41:05 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
2019-02-01 17:30:23 +08:00
|
|
|
// If a copy of the MIT was not distributed with gm file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-02-28 14:41:05 +08:00
|
|
|
|
2018-09-15 16:40:13 +08:00
|
|
|
// go test *.go -bench=".*" -benchmem
|
2018-02-28 14:41:05 +08:00
|
|
|
|
2019-05-13 22:26:39 +08:00
|
|
|
package gmap_test
|
2018-02-28 14:41:05 +08:00
|
|
|
|
|
|
|
import (
|
2019-06-19 09:06:52 +08:00
|
|
|
"strconv"
|
2019-05-13 22:26:39 +08:00
|
|
|
"testing"
|
2019-07-16 20:30:10 +08:00
|
|
|
|
2019-07-29 21:01:19 +08:00
|
|
|
"github.com/gogf/gf/container/gmap"
|
2018-02-28 14:41:05 +08:00
|
|
|
)
|
|
|
|
|
2019-08-26 23:35:44 +08:00
|
|
|
var anyAnyMap = gmap.NewAnyAnyMap(true)
|
|
|
|
var intIntMap = gmap.NewIntIntMap(true)
|
|
|
|
var intAnyMap = gmap.NewIntAnyMap(true)
|
|
|
|
var intStrMap = gmap.NewIntStrMap(true)
|
|
|
|
var strIntMap = gmap.NewStrIntMap(true)
|
|
|
|
var strAnyMap = gmap.NewStrAnyMap(true)
|
|
|
|
var strStrMap = gmap.NewStrStrMap(true)
|
2018-02-28 14:41:05 +08:00
|
|
|
|
2018-07-26 13:00:04 +08:00
|
|
|
func Benchmark_IntIntMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
intIntMap.Set(i, i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-02-28 14:41:05 +08:00
|
|
|
}
|
|
|
|
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_IntAnyMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
intAnyMap.Set(i, i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-02-28 14:41:05 +08:00
|
|
|
}
|
|
|
|
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_IntStrMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
intStrMap.Set(i, "123456789")
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-02-28 14:41:05 +08:00
|
|
|
}
|
|
|
|
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_AnyAnyMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
anyAnyMap.Set(i, i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-02-28 14:41:05 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 20:30:10 +08:00
|
|
|
// Note that there's additional performance cost for string conversion.
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_StrIntMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
strIntMap.Set(strconv.Itoa(i), i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-02-28 15:32:52 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 20:30:10 +08:00
|
|
|
// Note that there's additional performance cost for string conversion.
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_StrAnyMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
strAnyMap.Set(strconv.Itoa(i), i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-02-28 15:32:52 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 20:30:10 +08:00
|
|
|
// Note that there's additional performance cost for string conversion.
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_StrStrMap_Set(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
strStrMap.Set(strconv.Itoa(i), "123456789")
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-02-28 15:32:52 +08:00
|
|
|
}
|
|
|
|
|
2018-07-26 13:00:04 +08:00
|
|
|
func Benchmark_IntIntMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
intIntMap.Get(i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-07-26 13:00:04 +08:00
|
|
|
}
|
|
|
|
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_IntAnyMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
intAnyMap.Get(i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-07-26 13:00:04 +08:00
|
|
|
}
|
|
|
|
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_IntStrMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
intStrMap.Get(i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-07-26 13:00:04 +08:00
|
|
|
}
|
|
|
|
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_AnyAnyMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
anyAnyMap.Get(i)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-07-26 13:00:04 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 20:30:10 +08:00
|
|
|
// Note that there's additional performance cost for string conversion.
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_StrIntMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
strIntMap.Get(strconv.Itoa(i))
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-07-26 13:00:04 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 20:30:10 +08:00
|
|
|
// Note that there's additional performance cost for string conversion.
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_StrAnyMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
strAnyMap.Get(strconv.Itoa(i))
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-07-26 13:00:04 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 20:30:10 +08:00
|
|
|
// Note that there's additional performance cost for string conversion.
|
2019-05-08 17:21:18 +08:00
|
|
|
func Benchmark_StrStrMap_Get(b *testing.B) {
|
2019-07-16 20:30:10 +08:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
i := 0
|
|
|
|
for pb.Next() {
|
|
|
|
strStrMap.Get(strconv.Itoa(i))
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
})
|
2018-07-26 13:00:04 +08:00
|
|
|
}
|