github.com/sandwich-go/boost@v1.3.29/xerror/xerror_x_bench_test.go (about) 1 package xerror_test 2 3 import ( 4 "errors" 5 "github.com/sandwich-go/boost/xerror" 6 "testing" 7 ) 8 9 var ( 10 errBase = errors.New("test") 11 ) 12 13 func printIfError(b *testing.B, err error) { 14 if err != nil { 15 b.Error(err) 16 } 17 } 18 19 func Benchmark_NewText(b *testing.B) { 20 for i := 0; i < b.N; i++ { 21 printIfError(b, xerror.NewText("test")) 22 } 23 } 24 25 func Benchmark_NewText_Format(b *testing.B) { 26 for i := 0; i < b.N; i++ { 27 printIfError(b, xerror.NewText("%s", "test")) 28 } 29 } 30 31 func Benchmark_Wrap(b *testing.B) { 32 for i := 0; i < b.N; i++ { 33 printIfError(b, xerror.Wrap(errBase, "test")) 34 } 35 } 36 37 func Benchmark_Wrap_Format(b *testing.B) { 38 for i := 0; i < b.N; i++ { 39 printIfError(b, xerror.Wrap(errBase, "%s", "test")) 40 } 41 } 42 func Benchmark_NewCode(b *testing.B) { 43 for i := 0; i < b.N; i++ { 44 printIfError(b, xerror.NewCode(500, "test")) 45 } 46 } 47 48 func Benchmark_NewCode_Format(b *testing.B) { 49 for i := 0; i < b.N; i++ { 50 printIfError(b, xerror.NewCode(500, "%s", "test")) 51 } 52 } 53 54 func Benchmark_WrapCode(b *testing.B) { 55 for i := 0; i < b.N; i++ { 56 printIfError(b, xerror.WrapCode(500, errBase, "test")) 57 } 58 } 59 60 func Benchmark_WrapCode_Format(b *testing.B) { 61 for i := 0; i < b.N; i++ { 62 printIfError(b, xerror.WrapCode(500, errBase, "test")) 63 } 64 }