Groups
Groups
Sign in
Groups
Groups
golang-nuts
Conversations
About
Send feedback
Help
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 AM
6/22/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
The benchmark code:
https://play.golang.org/p/qp6wQgqcHKW
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