github.com/gogf/gf/v2@v2.7.4/errors/gerror/gerror_z_bench_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gerror_test 8 9 import ( 10 "errors" 11 "testing" 12 13 "github.com/gogf/gf/v2/errors/gcode" 14 "github.com/gogf/gf/v2/errors/gerror" 15 ) 16 17 var ( 18 // base error for benchmark testing of Wrap* functions. 19 baseError = errors.New("test") 20 ) 21 22 func Benchmark_New(b *testing.B) { 23 for i := 0; i < b.N; i++ { 24 gerror.New("test") 25 } 26 } 27 28 func Benchmark_Newf(b *testing.B) { 29 for i := 0; i < b.N; i++ { 30 gerror.Newf("%s", "test") 31 } 32 } 33 34 func Benchmark_Wrap(b *testing.B) { 35 for i := 0; i < b.N; i++ { 36 gerror.Wrap(baseError, "test") 37 } 38 } 39 40 func Benchmark_Wrapf(b *testing.B) { 41 for i := 0; i < b.N; i++ { 42 gerror.Wrapf(baseError, "%s", "test") 43 } 44 } 45 46 func Benchmark_NewSkip(b *testing.B) { 47 for i := 0; i < b.N; i++ { 48 gerror.NewSkip(1, "test") 49 } 50 } 51 52 func Benchmark_NewSkipf(b *testing.B) { 53 for i := 0; i < b.N; i++ { 54 gerror.NewSkipf(1, "%s", "test") 55 } 56 } 57 58 func Benchmark_NewCode(b *testing.B) { 59 for i := 0; i < b.N; i++ { 60 gerror.NewCode(gcode.New(500, "", nil), "test") 61 } 62 } 63 64 func Benchmark_NewCodef(b *testing.B) { 65 for i := 0; i < b.N; i++ { 66 gerror.NewCodef(gcode.New(500, "", nil), "%s", "test") 67 } 68 } 69 70 func Benchmark_NewCodeSkip(b *testing.B) { 71 for i := 0; i < b.N; i++ { 72 gerror.NewCodeSkip(gcode.New(1, "", nil), 500, "test") 73 } 74 } 75 76 func Benchmark_NewCodeSkipf(b *testing.B) { 77 for i := 0; i < b.N; i++ { 78 gerror.NewCodeSkipf(gcode.New(1, "", nil), 500, "%s", "test") 79 } 80 } 81 82 func Benchmark_WrapCode(b *testing.B) { 83 for i := 0; i < b.N; i++ { 84 gerror.WrapCode(gcode.New(500, "", nil), baseError, "test") 85 } 86 } 87 88 func Benchmark_WrapCodef(b *testing.B) { 89 for i := 0; i < b.N; i++ { 90 gerror.WrapCodef(gcode.New(500, "", nil), baseError, "test") 91 } 92 }