Most of the projects we use both bytes
as well strings
data structures. I wanted to know the difference further:
A []byte
is immutable and essentially just this:
type slice struct {
data uintptr
len int
cap int
}
And a string
is mutable and essentially just this:
type string struct {
data uintptr
len int
}
I was curios to know about the performance
of both and found a neat project. Findings of that project:
strings are faster for searches (contains, index, compare) purpose.
[]byte are faster in create (replace, concat) purpose.
To conclude, the comparision is like Apples and Oranges. Both have their own usecases string
has been used much more widely for its ease. Decision should be made from initial analysis to choose the type of data type.
Happy Coding