From d0e5f819badab10c65642eeb9b54034afc6f692f Mon Sep 17 00:00:00 2001 From: John Date: Wed, 18 Apr 2018 11:08:40 +0800 Subject: [PATCH] =?UTF-8?q?map=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geg/other/map/map_test.go | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 geg/other/map/map_test.go diff --git a/geg/other/map/map_test.go b/geg/other/map/map_test.go new file mode 100644 index 000000000..09ab75b31 --- /dev/null +++ b/geg/other/map/map_test.go @@ -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) + } +} \ No newline at end of file