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

Sergey Tsypanov stsypanov at openjdk.org
Tue Apr 18 18:49:56 UTC 2023


On Sun, 16 Apr 2023 11:20:46 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: Extract separate benchmark

With latest changes

baseline

Benchmark                                                                     Mode  Cnt      Score     Error   Units
DateTimeFormatterWithPaddingBench.formatWithPadding                          thrpt   15   5848.753 ± 223.592  ops/ms
DateTimeFormatterWithPaddingBench.formatWithPadding:·gc.alloc.rate           thrpt   15   1070.358 ±  40.881  MB/sec
DateTimeFormatterWithPaddingBench.formatWithPadding:·gc.alloc.rate.norm      thrpt   15    192.000 ±   0.001    B/op
DateTimeFormatterWithPaddingBench.formatWithPadding:·gc.count                thrpt   15     53.000            counts
DateTimeFormatterWithPaddingBench.formatWithPadding:·gc.time                 thrpt   15    479.000                ms
DateTimeFormatterWithPaddingBench.formatWithZeroPadding                      thrpt   15  22032.107 ± 481.443  ops/ms
DateTimeFormatterWithPaddingBench.formatWithZeroPadding:·gc.alloc.rate       thrpt   15   3192.003 ±  69.901  MB/sec
DateTimeFormatterWithPaddingBench.formatWithZeroPadding:·gc.alloc.rate.norm  thrpt   15    152.000 ±   0.001    B/op
DateTimeFormatterWithPaddingBench.formatWithZeroPadding:·gc.count            thrpt   15     83.000            counts
DateTimeFormatterWithPaddingBench.formatWithZeroPadding:·gc.time             thrpt   15   1046.000                ms

patch

Benchmark                                                                     Mode  Cnt      Score     Error   Units
DateTimeFormatterWithPaddingBench.formatWithPadding                          thrpt   15   7982.747 ± 374.638  ops/ms
DateTimeFormatterWithPaddingBench.formatWithPadding:·gc.alloc.rate           thrpt   15   1704.393 ±  80.063  MB/sec
DateTimeFormatterWithPaddingBench.formatWithPadding:·gc.alloc.rate.norm      thrpt   15    224.000 ±   0.001    B/op
DateTimeFormatterWithPaddingBench.formatWithPadding:·gc.count                thrpt   15     64.000            counts
DateTimeFormatterWithPaddingBench.formatWithPadding:·gc.time                 thrpt   15    641.000                ms
DateTimeFormatterWithPaddingBench.formatWithZeroPadding                      thrpt   15  22024.559 ± 794.713  ops/ms
DateTimeFormatterWithPaddingBench.formatWithZeroPadding:·gc.alloc.rate       thrpt   15   3190.932 ± 115.145  MB/sec
DateTimeFormatterWithPaddingBench.formatWithZeroPadding:·gc.alloc.rate.norm  thrpt   15    152.000 ±   0.001    B/op
DateTimeFormatterWithPaddingBench.formatWithZeroPadding:·gc.count            thrpt   15     85.000            counts
DateTimeFormatterWithPaddingBench.formatWithZeroPadding:·gc.time             thrpt   15   1019.000                ms

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

PR Comment: https://git.openjdk.org/jdk/pull/12131#issuecomment-1513638998


More information about the i18n-dev mailing list