From 0ca305a1bf33c4603d8cc215b2d9005f3c4cf2d6 Mon Sep 17 00:00:00 2001 From: John Guo Date: Fri, 11 Dec 2020 01:08:15 +0800 Subject: [PATCH] improve package gerror --- errors/gerror/gerror_stack.go | 2 ++ errors/gerror/gerror_z_bench_test.go | 17 +++++++++++++++++ .../{gerror_test.go => gerror_z_unit_test.go} | 0 3 files changed, 19 insertions(+) create mode 100644 errors/gerror/gerror_z_bench_test.go rename errors/gerror/{gerror_test.go => gerror_z_unit_test.go} (100%) diff --git a/errors/gerror/gerror_stack.go b/errors/gerror/gerror_stack.go index bcf54cad3..d5fbb3ffb 100644 --- a/errors/gerror/gerror_stack.go +++ b/errors/gerror/gerror_stack.go @@ -12,10 +12,12 @@ import "runtime" type stack []uintptr const ( + // maxStackDepth marks the max stack depth for error back traces. maxStackDepth = 32 ) // callers returns the stack callers. +// Note that it here just retrieves the caller memory address array not the caller information. func callers(skip ...int) stack { var ( pcs [maxStackDepth]uintptr diff --git a/errors/gerror/gerror_z_bench_test.go b/errors/gerror/gerror_z_bench_test.go new file mode 100644 index 000000000..6877780d8 --- /dev/null +++ b/errors/gerror/gerror_z_bench_test.go @@ -0,0 +1,17 @@ +// Copyright GoFrame 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 this file, +// You can obtain one at https://github.com/gogf/gf. + +package gerror + +import ( + "testing" +) + +func Benchmark_Stack(b *testing.B) { + for i := 0; i < b.N; i++ { + callers() + } +} diff --git a/errors/gerror/gerror_test.go b/errors/gerror/gerror_z_unit_test.go similarity index 100% rename from errors/gerror/gerror_test.go rename to errors/gerror/gerror_z_unit_test.go