diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
commit | b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch) | |
tree | d2caec2610d4ea887803ec9e9c3cd77136c448ba /dependencies/pkg/mod/golang.org/x/xerrors@v0.0.0-20220907171357-04be3eba64a2/stack_test.go | |
parent | Initial commit. (diff) | |
download | icingadb-upstream.tar.xz icingadb-upstream.zip |
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dependencies/pkg/mod/golang.org/x/xerrors@v0.0.0-20220907171357-04be3eba64a2/stack_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/golang.org/x/xerrors@v0.0.0-20220907171357-04be3eba64a2/stack_test.go b/dependencies/pkg/mod/golang.org/x/xerrors@v0.0.0-20220907171357-04be3eba64a2/stack_test.go new file mode 100644 index 0000000..e13f319 --- /dev/null +++ b/dependencies/pkg/mod/golang.org/x/xerrors@v0.0.0-20220907171357-04be3eba64a2/stack_test.go @@ -0,0 +1,60 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package xerrors_test + +import ( + "bytes" + "fmt" + "math/big" + "testing" + + "golang.org/x/xerrors" + "golang.org/x/xerrors/internal" +) + +type myType struct{} + +func (myType) Format(s fmt.State, v rune) { + s.Write(bytes.Repeat([]byte("Hi! "), 10)) +} + +func BenchmarkErrorf(b *testing.B) { + err := xerrors.New("foo") + // pi := big.NewFloat(3.14) // Something expensive. + num := big.NewInt(5) + args := func(a ...interface{}) []interface{} { return a } + benchCases := []struct { + name string + format string + args []interface{} + }{ + {"no_format", "msg: %v", args(err)}, + {"with_format", "failed %d times: %v", args(5, err)}, + {"method: mytype", "pi: %v", args("myfile.go", myType{}, err)}, + {"method: number", "pi: %v", args("myfile.go", num, err)}, + } + for _, bc := range benchCases { + b.Run(bc.name, func(b *testing.B) { + b.Run("ExpWithTrace", func(b *testing.B) { + for i := 0; i < b.N; i++ { + xerrors.Errorf(bc.format, bc.args...) + } + }) + b.Run("ExpNoTrace", func(b *testing.B) { + internal.EnableTrace = false + defer func() { internal.EnableTrace = true }() + + for i := 0; i < b.N; i++ { + xerrors.Errorf(bc.format, bc.args...) + } + }) + b.Run("Core", func(b *testing.B) { + for i := 0; i < b.N; i++ { + fmt.Errorf(bc.format, bc.args...) + } + }) + }) + } +} |