|
Performance of java.nio.CharBuffer vs. java.lang.StringBuffer:
Iterations |
CharBuffer |
StringBuffer |
% diff |
10000 |
~0 |
~0 |
0 |
1000000 |
187 |
243 |
77 |
For "normal" string processing there appears to be no difference between the two -- the effects are lost in the noise. For large strings (documents and the like), CharBuffer has a distinct advantage.
CharBuffer has the perk of pointer-like manipulation via CharBuffer.subSequence() and CharBuffer.slice() but lacks good string searching functions like StringBuffer.lasIndexOf().
The only caveat with CharBuffer is that the size of the buffer must be known a priori.
Notes:
- The length of the strings added were between
0 and 10 characters in length to simulate standard text processing.
- This should be taken with a grain of salt since it is a micro-benchmark.
|