string(aByteSlice) will duplicate undrelying bytes on stack if len(aByteSlice) <= 32

64 views
Skip to first unread message

tapi...@gmail.com

unread,
Jun 22, 2021, 8:44:56 AM6/22/21
to golang-nuts


The result:

Benchmark_CompareWithSwitch0Bytes-4        328873778             3.619 ns/op           0 B/op           0 allocs/op
Benchmark_CompareWithSwitch32Bytes-4       175067815             6.251 ns/op           0 B/op           0 allocs/op
Benchmark_CompareWithSwitch33Bytes-4       25879508            42.86 ns/op          48 B/op           1 allocs/op

It looks there is still a duplication cost if the slice length <= 32. But the benchmark result doesn't reflect this. Does the duplication happen on stack?
Reply all
Reply to author
Forward
0 new messages