github.com/zhongdalu/gf@v1.0.0/g/util/gconv/gconv_z_bench_str_test.go (about) 1 // Copyright 2017-2018 gf Author(https://github.com/zhongdalu/gf). 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/zhongdalu/gf. 6 7 // go test *.go -bench=".*" -benchmem 8 9 package gconv 10 11 import ( 12 "testing" 13 ) 14 15 var valueStr = "123456789" 16 17 func Benchmark_Str_To_String(b *testing.B) { 18 for i := 0; i < b.N; i++ { 19 String(valueStr) 20 } 21 } 22 23 func Benchmark_Str_To_Int(b *testing.B) { 24 for i := 0; i < b.N; i++ { 25 Int(valueStr) 26 } 27 } 28 29 func Benchmark_Str_To_Int8(b *testing.B) { 30 for i := 0; i < b.N; i++ { 31 Int8(valueStr) 32 } 33 } 34 35 func Benchmark_Str_To_Int16(b *testing.B) { 36 for i := 0; i < b.N; i++ { 37 Int16(valueStr) 38 } 39 } 40 41 func Benchmark_Str_To_Int32(b *testing.B) { 42 for i := 0; i < b.N; i++ { 43 Int32(valueStr) 44 } 45 } 46 47 func Benchmark_Str_To_Int64(b *testing.B) { 48 for i := 0; i < b.N; i++ { 49 Int(valueStr) 50 } 51 } 52 53 func Benchmark_Str_To_Uint(b *testing.B) { 54 for i := 0; i < b.N; i++ { 55 Uint(valueStr) 56 } 57 } 58 59 func Benchmark_Str_To_Uint8(b *testing.B) { 60 for i := 0; i < b.N; i++ { 61 Uint8(valueStr) 62 } 63 } 64 65 func Benchmark_Str_To_Uint16(b *testing.B) { 66 for i := 0; i < b.N; i++ { 67 Uint16(valueStr) 68 } 69 } 70 71 func Benchmark_Str_To_Uint32(b *testing.B) { 72 for i := 0; i < b.N; i++ { 73 Uint32(valueStr) 74 } 75 } 76 77 func Benchmark_Str_To_Uint64(b *testing.B) { 78 for i := 0; i < b.N; i++ { 79 Uint64(valueStr) 80 } 81 } 82 83 func Benchmark_Str_To_Float32(b *testing.B) { 84 for i := 0; i < b.N; i++ { 85 Float32(valueStr) 86 } 87 } 88 89 func Benchmark_Str_To_Float64(b *testing.B) { 90 for i := 0; i < b.N; i++ { 91 Float64(valueStr) 92 } 93 } 94 95 func Benchmark_Str_To_Time(b *testing.B) { 96 for i := 0; i < b.N; i++ { 97 Time(valueStr) 98 } 99 } 100 101 func Benchmark_Str_To_TimeDuration(b *testing.B) { 102 for i := 0; i < b.N; i++ { 103 Duration(valueStr) 104 } 105 } 106 107 func Benchmark_Str_To_Bytes(b *testing.B) { 108 for i := 0; i < b.N; i++ { 109 Bytes(valueStr) 110 } 111 } 112 113 func Benchmark_Str_To_Strings(b *testing.B) { 114 for i := 0; i < b.N; i++ { 115 Strings(valueStr) 116 } 117 } 118 119 func Benchmark_Str_To_Ints(b *testing.B) { 120 for i := 0; i < b.N; i++ { 121 Ints(valueStr) 122 } 123 } 124 125 func Benchmark_Str_To_Floats(b *testing.B) { 126 for i := 0; i < b.N; i++ { 127 Floats(valueStr) 128 } 129 } 130 131 func Benchmark_Str_To_Interfaces(b *testing.B) { 132 for i := 0; i < b.N; i++ { 133 Interfaces(valueStr) 134 } 135 }