github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/xstring/convert_bench_test.go (about) 1 package xstring 2 3 import ( 4 "testing" 5 ) 6 7 // Test the performance of the standard conversion string() 8 func Benchmark_StdFromBytes(b *testing.B) { 9 b.ReportAllocs() 10 x := []byte("Hello world! Hello world! Hello world!") 11 for i := 0; i < b.N; i++ { 12 _ = string(x) 13 } 14 } 15 16 // Test the performance of strong conversion []byte to string 17 func Benchmark_FromBytes(b *testing.B) { 18 b.ReportAllocs() 19 x := []byte("Hello world! Hello world! Hello world!") 20 for i := 0; i < b.N; i++ { 21 _ = FromBytes(x) 22 } 23 } 24 25 // Test the performance of standard conversion []byte 26 func Benchmark_StdToBytes(b *testing.B) { 27 b.ReportAllocs() 28 x := "Hello world! Hello world! Hello world!" 29 for i := 0; i < b.N; i++ { 30 _ = []byte(x) 31 } 32 } 33 34 // Test the performance of strong conversion string to []byte 35 func Benchmark_ToBytes(b *testing.B) { 36 b.ReportAllocs() 37 x := "Hello world! Hello world! Hello world!" 38 for i := 0; i < b.N; i++ { 39 _ = ToBytes(x) 40 } 41 }