Buffer | 37322 ns/op | 51104 B/op | 10 allocs/op |
Array | 49456 ns/op | 53632 B/op | 17 allocs/op |
Linked | 122558 ns/op | 54047 B/op | 1010 allocs/op |
Merge | 311005 ns/op | 323552 B/op | 1998 allocs/op |
Naive | 2225408 ns/op | 5371680 B/op | 999 allocs/op |
An "op" in this case was appending 10 characters, 1000 times.
Some observations:
- Naive concatenation is indeed bad, both in speed and memory
- Almost anything is much better than the naive approach
- As expected, a buffer is the best in both speed and memory
- An array of substrings (without any merging) does surprisingly well
- For an immutable option, a linked list isn't too bad
- A merge tree was not such a good idea
No comments:
Post a Comment