8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
Brian Burkhalter
brian.burkhalter at oracle.com
Thu Feb 21 20:30:29 UTC 2019
> On Feb 21, 2019, at 10:07 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
>
>
>> On Feb 21, 2019, at 9:57 AM, Alan Bateman <Alan.Bateman at oracle.com <mailto:Alan.Bateman at oracle.com>> wrote:
>>
>>> Updated patch below. It’s a little unclear where to put ‘pos = position()’.
>> remaining() also reads the position so I think you want:
>>
>> int pos = src.position();
>> int lim = src.limit();
>> int rem = (pos <= lim) ? lim - pos : 0;
>
> Oh, your are correct but I don’t think we want “src.”
I created a webrev including an updated benchmark:
http://cr.openjdk.java.net/~bpb/8011135/webrev/
Before and after results are:
— Before —
Benchmark (numChars) Mode Cnt Score Error Units
CharBuffers.putString 2 avgt 5 11.546 ± 1.070 ns/op
CharBuffers.putString 256 avgt 5 287.714 ± 11.479 ns/op
CharBuffers.putString 16384 avgt 5 16768.276 ± 110.839 ns/op
— After —
Benchmark (numChars) Mode Cnt Score Error Units
CharBuffers.putString 2 avgt 5 10.790 ± 0.394 ns/op
CharBuffers.putString 256 avgt 5 18.867 ± 0.402 ns/op
CharBuffers.putString 16384 avgt 5 1218.156 ± 25.454 ns/op
Thanks,
Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190221/98f60bd9/attachment-0001.html>
More information about the nio-dev
mailing list