<i18n dev> RFR: 8300818: Reduce complexity of padding with DateTimeFormatter [v3]

Roger Riggs rriggs at openjdk.org
Wed Apr 12 17:44:47 UTC 2023


On Mon, 10 Apr 2023 14:01:53 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains six additional commits since the last revision:
> 
>  - Merge branch 'master' into dtfb
>  - 8300818: Add benchmark
>  - 8300818: Add benchmark
>  - Revert irrelevant change
>  - Merge branch 'master' into dtfb
>  - Improve padding of DateTimeFormatter

test/micro/org/openjdk/bench/java/time/format/DateTimeFormatterBench.java line 148:

> 146:         return YEAR_FORMATTER.format(now);
> 147:     }
> 148: 

There benchmarks are run 4 time each because of the @Param that are defined for the pre-existing tests.
I don't know if jmh can be annotated to ignore the params; but to avoid wasting resources create a separate jmh source file for thees new tests.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/12131#discussion_r1164450924


More information about the i18n-dev mailing list