gf/container/gmap/gmap_z_bench_safe_test.go
2019-07-29 21:01:19 +08:00

171 lines
3.2 KiB
Go

// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// 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 (
"strconv"
"testing"
"github.com/gogf/gf/container/gmap"
)
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()
func Benchmark_IntIntMap_Set(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
intIntMap.Set(i, i)
i++
}
})
}
func Benchmark_IntAnyMap_Set(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
intAnyMap.Set(i, i)
i++
}
})
}
func Benchmark_IntStrMap_Set(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
intStrMap.Set(i, "123456789")
i++
}
})
}
func Benchmark_AnyAnyMap_Set(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
anyAnyMap.Set(i, i)
i++
}
})
}
// Note that there's additional performance cost for string conversion.
func Benchmark_StrIntMap_Set(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
strIntMap.Set(strconv.Itoa(i), i)
i++
}
})
}
// Note that there's additional performance cost for string conversion.
func Benchmark_StrAnyMap_Set(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
strAnyMap.Set(strconv.Itoa(i), i)
i++
}
})
}
// Note that there's additional performance cost for string conversion.
func Benchmark_StrStrMap_Set(b *testing.B) {
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) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
intIntMap.Get(i)
i++
}
})
}
func Benchmark_IntAnyMap_Get(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
intAnyMap.Get(i)
i++
}
})
}
func Benchmark_IntStrMap_Get(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
intStrMap.Get(i)
i++
}
})
}
func Benchmark_AnyAnyMap_Get(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
anyAnyMap.Get(i)
i++
}
})
}
// Note that there's additional performance cost for string conversion.
func Benchmark_StrIntMap_Get(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
strIntMap.Get(strconv.Itoa(i))
i++
}
})
}
// Note that there's additional performance cost for string conversion.
func Benchmark_StrAnyMap_Get(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
strAnyMap.Get(strconv.Itoa(i))
i++
}
})
}
// Note that there's additional performance cost for string conversion.
func Benchmark_StrStrMap_Get(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
strStrMap.Get(strconv.Itoa(i))
i++
}
})
}