<i18n dev> RFR: 8300818: Reduce complexity of padding with DateTimeFormatter [v2]
Sergey Tsypanov
stsypanov at openjdk.org
Fri Mar 24 19:34:33 UTC 2023
On Sun, 22 Jan 2023 09:50:21 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 two additional commits since the last revision:
>
> - Merge branch 'master' into dtfb
> - Improve padding of DateTimeFormatter
Benchmarking:
make test TEST="micro:time.format.DateTimeFormatterBench" MICRO="OPTIONS=-prof gc"
master
Benchmark Mode Cnt Score Error Units
DateTimeFormatterBench.formatWithPadding thrpt 15 1621.744 ± 216.203 ops/ms
DateTimeFormatterBench.formatWithPadding:·gc.alloc.rate thrpt 15 295.938 ± 39.238 MB/sec
DateTimeFormatterBench.formatWithPadding:·gc.alloc.rate.norm thrpt 15 192.000 ± 0.001 B/op
DateTimeFormatterBench.formatWithPadding:·gc.count thrpt 15 23.000 counts
DateTimeFormatterBench.formatWithPadding:·gc.time thrpt 15 353.000 ms
DateTimeFormatterBench.formatWithZeroPadding thrpt 15 2787.775 ± 1383.428 ops/ms
DateTimeFormatterBench.formatWithZeroPadding:·gc.alloc.rate thrpt 15 401.775 ± 201.097 MB/sec
DateTimeFormatterBench.formatWithZeroPadding:·gc.alloc.rate.norm thrpt 15 152.000 ± 0.001 B/op
DateTimeFormatterBench.formatWithZeroPadding:·gc.count thrpt 15 22.000 counts
DateTimeFormatterBench.formatWithZeroPadding:·gc.time thrpt 15 396.000 ms
dtfb
Benchmark Mode Cnt Score Error Units
DateTimeFormatterBench.formatWithPadding thrpt 15 5489.480 ± 200.120 ops/ms
DateTimeFormatterBench.formatWithPadding:·gc.alloc.rate thrpt 15 1171.637 ± 42.648 MB/sec
DateTimeFormatterBench.formatWithPadding:·gc.alloc.rate.norm thrpt 15 224.000 ± 0.001 B/op
DateTimeFormatterBench.formatWithPadding:·gc.count thrpt 15 62.000 counts
DateTimeFormatterBench.formatWithPadding:·gc.time thrpt 15 342.000 ms
DateTimeFormatterBench.formatWithZeroPadding thrpt 15 14355.239 ± 640.377 ops/ms
DateTimeFormatterBench.formatWithZeroPadding:·gc.alloc.rate thrpt 15 2078.802 ± 93.278 MB/sec
DateTimeFormatterBench.formatWithZeroPadding:·gc.alloc.rate.norm thrpt 15 152.000 ± 0.001 B/op
DateTimeFormatterBench.formatWithZeroPadding:·gc.count thrpt 15 77.000 counts
DateTimeFormatterBench.formatWithZeroPadding:·gc.time thrpt 15 555.000 ms
-------------
PR Comment: https://git.openjdk.org/jdk/pull/12131#issuecomment-1483302436
More information about the i18n-dev
mailing list