MCPcopy Index your code
hub / github.com/cockroachdb/errors / BenchmarkErrorsIs

Function BenchmarkErrorsIs

benchmark_test.go:12–181  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

10)
11
12func BenchmarkErrorsIs(b *testing.B) {
13 b.Run("NilError", func(b *testing.B) {
14 var err error
15 for range b.N {
16 errors.Is(err, context.Canceled)
17 }
18 })
19
20 b.Run("SimpleError", func(b *testing.B) {
21 err := errors.New("test")
22 for range b.N {
23 errors.Is(err, context.Canceled)
24 }
25 })
26
27 b.Run("WrappedError", func(b *testing.B) {
28 baseErr := errors.New("test")
29 err := errors.Wrap(baseErr, "wrapped error")
30 for range b.N {
31 errors.Is(err, context.Canceled)
32 }
33 })
34
35 b.Run("WrappedWithStack", func(b *testing.B) {
36 baseErr := errors.New("test")
37 err := errors.WithStack(baseErr)
38 for range b.N {
39 errors.Is(err, context.Canceled)
40 }
41 })
42
43 b.Run("NetworkError", func(b *testing.B) {
44 netErr := &net.OpError{
45 Op: "dial",
46 Net: "tcp",
47 Addr: &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 26257},
48 Err: fmt.Errorf("connection refused"),
49 }
50 err := errors.Wrap(netErr, "network connection failed")
51 for range b.N {
52 errors.Is(err, context.Canceled)
53 }
54 })
55
56 b.Run("DeeplyWrappedNetworkError", func(b *testing.B) {
57 netErr := &net.OpError{
58 Op: "dial",
59 Net: "tcp",
60 Addr: &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 26257},
61 Err: fmt.Errorf("connection refused"),
62 }
63 err := errors.WithStack(netErr)
64 err = errors.Wrap(err, "failed to connect to database")
65 err = errors.Wrap(err, "unable to establish connection")
66 err = errors.WithStack(err)
67 for range b.N {
68 errors.Is(err, context.Canceled)
69 }

Callers

nothing calls this directly

Calls 6

IsFunction · 0.92
NewFunction · 0.92
WrapFunction · 0.92
WithStackFunction · 0.92
WithMessageFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…