mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 20:28:17 +08:00
80 lines
1.2 KiB
Go
80 lines
1.2 KiB
Go
// 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 gm file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
// go test *.go -bench=".*" -benchmem
|
|
|
|
package gmap_test
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/v2/container/gmap"
|
|
)
|
|
|
|
var gm = gmap.NewIntIntMap(true)
|
|
var sm = sync.Map{}
|
|
|
|
func Benchmark_GMapSet(b *testing.B) {
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
i := 0
|
|
for pb.Next() {
|
|
gm.Set(i, i)
|
|
i++
|
|
}
|
|
})
|
|
}
|
|
|
|
func Benchmark_SyncMapSet(b *testing.B) {
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
i := 0
|
|
for pb.Next() {
|
|
sm.Store(i, i)
|
|
i++
|
|
}
|
|
})
|
|
}
|
|
|
|
func Benchmark_GMapGet(b *testing.B) {
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
i := 0
|
|
for pb.Next() {
|
|
gm.Get(i)
|
|
i++
|
|
}
|
|
})
|
|
}
|
|
|
|
func Benchmark_SyncMapGet(b *testing.B) {
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
i := 0
|
|
for pb.Next() {
|
|
sm.Load(i)
|
|
i++
|
|
}
|
|
})
|
|
}
|
|
|
|
func Benchmark_GMapRemove(b *testing.B) {
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
i := 0
|
|
for pb.Next() {
|
|
gm.Remove(i)
|
|
i++
|
|
}
|
|
})
|
|
}
|
|
|
|
func Benchmark_SyncMapRmove(b *testing.B) {
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
i := 0
|
|
for pb.Next() {
|
|
sm.Delete(i)
|
|
i++
|
|
}
|
|
})
|
|
}
|