RFR: 8300818: Reduce complexity of padding with DateTimeFormatter [v7]
Roger Riggs
rriggs at openjdk.org
Fri Apr 21 19:28:47 UTC 2023
On Fri, 21 Apr 2023 17:45:50 GMT, Sergey Tsypanov <stsypanov at openjdk.org> wrote:
>> Currently it's O(n) - we do `n` shifts of bytes within `StringBuilder`. This can be reduced to O(1) improving the code like:
>>
>> DateTimeFormatter dtf = new DateTimeFormatterBuilder()
>> .appendLiteral("Date:")
>> .padNext(20, ' ')
>> .append(DateTimeFormatter.ISO_DATE)
>> .toFormatter();
>> String text = dtf.format(LocalDateTime.now());
>
> Sergey Tsypanov has updated the pull request incrementally with one additional commit since the last revision:
>
> 8300818: One more benchmark
Marked as reviewed by rriggs (Reviewer).
I added a few more small padding cases and and re-ran on my Mac:
Baseline:
Benchmark Mode Cnt Score Error Units
DateTimeFormatterWithPaddingBench.formatWithPadding thrpt 15 5167.611 ± 85.096 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength0 thrpt 15 22004.618 ± 536.207 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength1 thrpt 15 18041.569 ± 142.627 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength2 thrpt 15 15966.853 ± 182.284 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength3 thrpt 15 13472.887 ± 181.794 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength4 thrpt 15 12991.458 ± 402.190 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength5 thrpt 15 11464.481 ± 603.970 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength6 thrpt 15 10386.347 ± 673.596 ops/ms
Patch:
Benchmark Mode Cnt Score Error Units
DateTimeFormatterWithPaddingBench.formatWithPadding thrpt 15 6548.853 ± 201.695 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength0 thrpt 15 22269.428 ± 737.613 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength1 thrpt 15 19086.146 ± 117.055 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength2 thrpt 15 15627.898 ± 314.890 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength3 thrpt 15 15447.997 ± 121.946 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength4 thrpt 15 15185.318 ± 198.266 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength5 thrpt 15 15243.618 ± 147.131 ops/ms
DateTimeFormatterWithPaddingBench.formatWithPaddingLength6 thrpt 15 15093.142 ± 294.421 ops/ms
The expected steps in performance match the code paths of 0, 1, 2-6.
-------------
PR Review: https://git.openjdk.org/jdk/pull/12131#pullrequestreview-1396300114
PR Comment: https://git.openjdk.org/jdk/pull/12131#issuecomment-1518248669
More information about the core-libs-dev
mailing list