|
|
|
|
|
by supersillyus
5133 days ago
|
|
For what it's worth, I've looked into the 'Split' case, and the performance difference when specialized to the single-byte case is about 2%, which is mostly because Split already has built-in specialization for the single-byte case, which amounts to a couple extra instructions in a function whose running time is dominated by allocation. I think they made the right choice there; the Go team seems very good about optimizing only where it matters; there's lots of low hanging fruit, but the majority of it isn't very useful fruit. |
|
I did 128 runs on a byte array of length 2^24. It has delimiters placed at positions {2^i, i < 24}.
I tested my implementation against both the "bytes" package implementation, and a copy of the relevant portions of the "bytes" package (to account for any odd effects of inlining and separate compilation). I did the set of timings twice in case there was any GC.
Here's the wall time in milliseconds for the three implementations, on a 2010 Macbook Air.
mine 3313 copy 4709 bytes 5689 mine 3327 copy 4660 bytes 5660
My single-byte implementation is about 40% faster than the local version, and 70% faster than the "bytes" version. Not quite twice, but I wasn't far off.
But aside from performance, there is just consistency of interface. Once you've established a 'Byte' variant of some functions, you should do it for all the common functions.