github.com/gogf/gf/v2@v2.7.4/util/gconv/gconv_z_bench_bytes_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  // go test *.go -bench "Benchmark_Bytes_To_*" -benchmem
     8  
     9  package gconv
    10  
    11  import (
    12  	"testing"
    13  	"unsafe"
    14  
    15  	"github.com/gogf/gf/v2/encoding/gbinary"
    16  )
    17  
    18  var valueBytes = gbinary.Encode(123456789)
    19  
    20  func Benchmark_Bytes_To_String_Normal(b *testing.B) {
    21  	for i := 0; i < b.N; i++ {
    22  		_ = string(valueBytes)
    23  	}
    24  }
    25  
    26  func Benchmark_Bytes_To_String_Unsafe(b *testing.B) {
    27  	for i := 0; i < b.N; i++ {
    28  		_ = *(*string)(unsafe.Pointer(&valueBytes))
    29  	}
    30  }
    31  
    32  func Benchmark_Bytes_To_String(b *testing.B) {
    33  	for i := 0; i < b.N; i++ {
    34  		String(valueBytes)
    35  	}
    36  }
    37  
    38  func Benchmark_Bytes_To_Int(b *testing.B) {
    39  	for i := 0; i < b.N; i++ {
    40  		Int(valueBytes)
    41  	}
    42  }
    43  
    44  func Benchmark_Bytes_To_Int8(b *testing.B) {
    45  	for i := 0; i < b.N; i++ {
    46  		Int8(valueBytes)
    47  	}
    48  }
    49  
    50  func Benchmark_Bytes_To_Int16(b *testing.B) {
    51  	for i := 0; i < b.N; i++ {
    52  		Int16(valueBytes)
    53  	}
    54  }
    55  
    56  func Benchmark_Bytes_To_Int32(b *testing.B) {
    57  	for i := 0; i < b.N; i++ {
    58  		Int32(valueBytes)
    59  	}
    60  }
    61  
    62  func Benchmark_Bytes_To_Int64(b *testing.B) {
    63  	for i := 0; i < b.N; i++ {
    64  		Int(valueBytes)
    65  	}
    66  }
    67  
    68  func Benchmark_Bytes_To_Uint(b *testing.B) {
    69  	for i := 0; i < b.N; i++ {
    70  		Uint(valueBytes)
    71  	}
    72  }
    73  
    74  func Benchmark_Bytes_To_Uint8(b *testing.B) {
    75  	for i := 0; i < b.N; i++ {
    76  		Uint8(valueBytes)
    77  	}
    78  }
    79  
    80  func Benchmark_Bytes_To_Uint16(b *testing.B) {
    81  	for i := 0; i < b.N; i++ {
    82  		Uint16(valueBytes)
    83  	}
    84  }
    85  
    86  func Benchmark_Bytes_To_Uint32(b *testing.B) {
    87  	for i := 0; i < b.N; i++ {
    88  		Uint32(valueBytes)
    89  	}
    90  }
    91  
    92  func Benchmark_Bytes_To_Uint64(b *testing.B) {
    93  	for i := 0; i < b.N; i++ {
    94  		Uint64(valueBytes)
    95  	}
    96  }
    97  
    98  func Benchmark_Bytes_To_Float32(b *testing.B) {
    99  	for i := 0; i < b.N; i++ {
   100  		Float32(valueBytes)
   101  	}
   102  }
   103  
   104  func Benchmark_Bytes_To_Float64(b *testing.B) {
   105  	for i := 0; i < b.N; i++ {
   106  		Float64(valueBytes)
   107  	}
   108  }
   109  
   110  func Benchmark_Bytes_To_Time(b *testing.B) {
   111  	for i := 0; i < b.N; i++ {
   112  		Time(valueBytes)
   113  	}
   114  }
   115  
   116  func Benchmark_Bytes_To_TimeDuration(b *testing.B) {
   117  	for i := 0; i < b.N; i++ {
   118  		Duration(valueBytes)
   119  	}
   120  }
   121  
   122  func Benchmark_Bytes_To_Bytes(b *testing.B) {
   123  	for i := 0; i < b.N; i++ {
   124  		Bytes(valueBytes)
   125  	}
   126  }
   127  
   128  func Benchmark_Bytes_To_Strings(b *testing.B) {
   129  	for i := 0; i < b.N; i++ {
   130  		Strings(valueBytes)
   131  	}
   132  }
   133  
   134  func Benchmark_Bytes_To_Ints(b *testing.B) {
   135  	for i := 0; i < b.N; i++ {
   136  		Ints(valueBytes)
   137  	}
   138  }
   139  
   140  func Benchmark_Bytes_To_Floats(b *testing.B) {
   141  	for i := 0; i < b.N; i++ {
   142  		Floats(valueBytes)
   143  	}
   144  }
   145  
   146  func Benchmark_Bytes_To_Interfaces(b *testing.B) {
   147  	for i := 0; i < b.N; i++ {
   148  		Interfaces(valueBytes)
   149  	}
   150  }