Files
gf/container/gmap/gmap_z_bench_syncmap_test.go

81 lines
1.3 KiB
Go
Raw Permalink Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). 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 this file,
// You can obtain one at https://github.com/gogf/gf.
2018-09-20 09:28:45 +08:00
// go test *.go -bench=".*" -benchmem
package gmap_test
import (
2019-06-19 09:06:52 +08:00
"sync"
"testing"
2019-07-16 20:30:10 +08:00
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/container/gmap"
)
2019-08-26 23:35:44 +08:00
var gm = gmap.NewIntIntMap(true)
2019-07-16 20:30:10 +08:00
var sm = sync.Map{}
2019-07-16 20:30:10 +08:00
func Benchmark_GMapSet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
gm.Set(i, i)
i++
}
})
}
2019-07-16 20:30:10 +08:00
func Benchmark_SyncMapSet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
sm.Store(i, i)
i++
}
})
}
2019-07-16 20:30:10 +08:00
func Benchmark_GMapGet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
gm.Get(i)
i++
}
})
}
2019-07-16 20:30:10 +08:00
func Benchmark_SyncMapGet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
sm.Load(i)
i++
}
})
}
2019-07-16 20:30:10 +08:00
func Benchmark_GMapRemove(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
gm.Remove(i)
i++
}
})
}
2019-07-16 20:30:10 +08:00
func Benchmark_SyncMapRmove(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
sm.Delete(i)
i++
}
})
}