I noticed that Andreas used CharBuffer in his initial patch for #45390. I was curious about the performance implications, so I wrote a little micro-benchmark. The results:
Sun Java 1.4.2_16: StringBuffer def: 6594 ms StringBuffer 1024: 6609 ms CharBuffer: 5250 ms Sun Java 1.5.0_14: StringBuffer def: 5375 ms StringBuffer 1024: 5375 ms CharBuffer: 5594 ms Sun Java 6.0_03: StringBuffer def: 2750 ms StringBuffer 1024: 2750 ms CharBuffer: 4719 ms Apache Harmony r618795: StringBuffer def: 4687 ms StringBuffer 1024: 4672 ms CharBuffer: 7766 ms So this is a single-threaded test. It might perform differently in a heavy multi-threading environment. Anyway, it looks it doesn't make much sense to use the CharBuffer instead of the more familiar StringBuffer for simple string concatenation. I'm sure there's a benefit in using CharBuffer in scenarios where nio can really show its muscles. Jeremias Maerki
CharBufferSpeedTest.java
Description: Binary data
