mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
map测试
This commit is contained in:
57
geg/other/map/map_test.go
Normal file
57
geg/other/map/map_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
// 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 test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var m1 = make(map[int]int)
|
||||
var m2 = make(map[interface{}]interface{})
|
||||
|
||||
func BenchmarkMapIntInt_Set(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
m1[i] = i
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMapIntInt_Search(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, ok := m1[i]; ok {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMapIntInt_Remove(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
delete(m1, i)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func BenchmarkMapInterface_Set(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
m2[i] = i
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMapInterface_Search(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, ok := m2[i]; ok {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMapInterface_Remove(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
delete(m2, i)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user