From aefbfd52e9eb267bb1e6e5ea316ae1751e1b4383 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 13 May 2019 22:37:05 +0800 Subject: [PATCH] add more example for gtree --- g/container/gmap/gmap_z_bench_maps_test.go | 55 ++++++++++++++++++++++ g/container/gmap/gmap_z_bench_safe_test.go | 1 - 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 g/container/gmap/gmap_z_bench_maps_test.go diff --git a/g/container/gmap/gmap_z_bench_maps_test.go b/g/container/gmap/gmap_z_bench_maps_test.go new file mode 100644 index 000000000..5194311d0 --- /dev/null +++ b/g/container/gmap/gmap_z_bench_maps_test.go @@ -0,0 +1,55 @@ +// Copyright 2017 gf Author(https://github.com/gogf/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 gm file, +// You can obtain one at https://github.com/gogf/gf. + +// go test *.go -bench=".*" -benchmem + +package gmap_test + +import ( + "github.com/gogf/gf/g/container/gmap" + "github.com/gogf/gf/g/util/gutil" + "testing" +) + +var hashMap = gmap.New() +var listMap = gmap.NewListMap() +var treeMap = gmap.NewTreeMap(gutil.ComparatorInt) + +func Benchmark_HashMap_Set(b *testing.B) { + for i := 0; i < b.N; i++ { + hashMap.Set(i, i) + } +} + +func Benchmark_ListMap_Set(b *testing.B) { + for i := 0; i < b.N; i++ { + listMap.Set(i, i) + } +} + +func Benchmark_TreeMap_Set(b *testing.B) { + for i := 0; i < b.N; i++ { + treeMap.Set(i, i) + } +} + +func Benchmark_HashMap_Get(b *testing.B) { + for i := 0; i < b.N; i++ { + hashMap.Get(i) + } +} + +func Benchmark_ListMap_Get(b *testing.B) { + for i := 0; i < b.N; i++ { + listMap.Get(i) + } +} + +func Benchmark_TreeMap_Get(b *testing.B) { + for i := 0; i < b.N; i++ { + treeMap.Get(i) + } +} diff --git a/g/container/gmap/gmap_z_bench_safe_test.go b/g/container/gmap/gmap_z_bench_safe_test.go index e40af2596..312ba1452 100644 --- a/g/container/gmap/gmap_z_bench_safe_test.go +++ b/g/container/gmap/gmap_z_bench_safe_test.go @@ -14,7 +14,6 @@ import ( "strconv" ) - var ififm = gmap.New() var iim = gmap.NewIntIntMap() var iifm = gmap.NewIntAnyMap()