diff options
author | Valery Piashchynski <[email protected]> | 2021-02-05 23:10:50 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-02-05 23:10:50 +0300 |
commit | 11b357c4457dfcbc1ef79478c200b794b5486b13 (patch) | |
tree | 29b512baf4d6a8ef79e19a0de3a9e642871b6d4e /pkg/pool/static_pool_test.go | |
parent | 6c8cf12de734f01a0f0cdc4d2b55973cc8d1ddf1 (diff) |
Faster toString convertation (only for the english)
Diffstat (limited to 'pkg/pool/static_pool_test.go')
-rwxr-xr-x | pkg/pool/static_pool_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/pool/static_pool_test.go b/pkg/pool/static_pool_test.go index 8b1bf6a9..65e10119 100755 --- a/pkg/pool/static_pool_test.go +++ b/pkg/pool/static_pool_test.go @@ -645,3 +645,34 @@ func Benchmark_Pool_Echo_Replaced(b *testing.B) { } } } + +// BenchmarkToStringUnsafe-12 566317729 1.91 ns/op 0 B/op 0 allocs/op +// inline BenchmarkToStringUnsafe-12 1000000000 0.295 ns/op 0 B/op 0 allocs/op +func BenchmarkToStringUnsafe(b *testing.B) { + testPayload := []byte("falsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtoj") + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + res := toString(testPayload) + _ = res + } +} + +// BenchmarkToStringSafe-12 28584489 39.1 ns/op 112 B/op 1 allocs/op +// inline BenchmarkToStringSafe-12 28926276 46.6 ns/op 128 B/op 1 allocs/op +func BenchmarkToStringSafe(b *testing.B) { + testPayload := []byte("falsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtoj") + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + res := toStringNotFun(testPayload) + _ = res + } +} + +func toStringNotFun(data []byte) string { + return string(data) +} |