mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 12:47:50 +08:00
完善gmap与sync.map的基准测试
This commit is contained in:
parent
5764462d81
commit
77d570721c
56
g/container/gmap/gmap_test.go
Normal file
56
g/container/gmap/gmap_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright 2017 gf Author(https://gitee.com/johng/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 this file,
|
||||||
|
// You can obtain one at https://gitee.com/johng/gf.
|
||||||
|
|
||||||
|
// go test *.go -bench=".*"
|
||||||
|
|
||||||
|
package gmap_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"gitee.com/johng/gf/g/container/gmap"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
var m1 = gmap.NewIntIntMap()
|
||||||
|
var m2 = sync.Map{}
|
||||||
|
|
||||||
|
func BenchmarkGmapSet(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
m1.Set(i, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSyncmapSet(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
m2.Store(i, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkGmapGet(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
m1.Get(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSyncmapGet(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
m2.Load(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkGmapRemove(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
m1.Remove(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSyncmapRmove(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
m2.Delete(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user