gf/container/gmap/gmap_z_bench_safe_test.go

171 lines
3.2 KiB
Go
Raw Normal View History

// 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,
// You can obtain one at https://github.com/gogf/gf.
2018-02-28 14:41:05 +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-07-16 20:30:10 +08:00
var anyAnyMap = gmap.NewAnyAnyMap()
var intIntMap = gmap.NewIntIntMap()
var intAnyMap = gmap.NewIntAnyMap()
var intStrMap = gmap.NewIntStrMap()
var strIntMap = gmap.NewStrIntMap()
var strAnyMap = gmap.NewStrAnyMap()
var strStrMap = gmap.NewStrStrMap()
2018-02-28 14:41:05 +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
}
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
}
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
}
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.
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++
}
})
}
2019-07-16 20:30:10 +08:00
// Note that there's additional performance cost for string conversion.
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++
}
})
}
2019-07-16 20:30:10 +08:00
// Note that there's additional performance cost for string conversion.
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++
}
})
}
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++
}
})
}
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++
}
})
}
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++
}
})
}
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++
}
})
}
2019-07-16 20:30:10 +08:00
// Note that there's additional performance cost for string conversion.
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++
}
})
}
2019-07-16 20:30:10 +08:00
// Note that there's additional performance cost for string conversion.
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++
}
})
}
2019-07-16 20:30:10 +08:00
// Note that there's additional performance cost for string conversion.
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++
}
})
}