From 77d570721c62c4b6f9bdc8e7debb5984b10f38c7 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 28 Feb 2018 14:41:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84gmap=E4=B8=8Esync.map?= =?UTF-8?q?=E7=9A=84=E5=9F=BA=E5=87=86=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/container/gmap/gmap_test.go | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 g/container/gmap/gmap_test.go diff --git a/g/container/gmap/gmap_test.go b/g/container/gmap/gmap_test.go new file mode 100644 index 000000000..6db373955 --- /dev/null +++ b/g/container/gmap/gmap_test.go @@ -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) + } +} +