Indeed confining the maximum time span to one day fixed the issue. Thanks
so much for the prompt response Carter!

On Tue, Oct 26, 2021 at 10:15 PM Carter Kozak <[email protected]> wrote:

> It looks like we're spending a great deal of time calculating midnight,
> and the delta to midnight. I don't think this is a representative benchmark
> because the time intervals  are not ordered, nor are they close together.
> This means the entire cache is invalidated each iteration (date, time, etc)
> because times are very far apart (cache is a total loss, rather than an
> optimization). We don't expect the midnight part of the calculation to be
> expensive because if you're logging one event per day, it doesn't really
> matter.
>
> If I update the benchmark to attempt 1000 instants which are ordered and
> set up in 1ms intervals, I get the following results:
> Benchmark                                      (pattern)   Mode  Cnt
> Score      Error  Units
> FormatterBenchmark.commonsFdf               HH:mm:ss.SSS  thrpt    4
> 10556.843 ±  348.698  ops/s
> FormatterBenchmark.commonsFdf  yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt    4
>  6967.302 ± 1305.847  ops/s
> FormatterBenchmark.javaDtf                  HH:mm:ss.SSS  thrpt    4
>  4095.345 ±  202.770  ops/s
> FormatterBenchmark.javaDtf     yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt    4
>  2977.085 ±  487.369  ops/s
> FormatterBenchmark.log4jFdf                 HH:mm:ss.SSS  thrpt    4
> 39175.861 ± 6159.347  ops/s
> FormatterBenchmark.log4jFdf    yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt    4
> 33468.856 ±  597.435  ops/s
>
> On Tue, Oct 26, 2021, at 15:22, Volkan Yazıcı wrote:
> > I always had the impression that Log4j `FixedDateFormat` is faster than
> > Commons `FastDateFormat` which is faster than Java `DateTimeFormatter`,
> > yet, unless I am doing something stupid, the picture is totally different
> > in Java 17:
> >
> >
> > *Benchmark                   (pattern)   Mode  Cnt     Score     Error
> > Units*commonsFdf               HH:mm:ss.SSS  thrpt   12  6749.822 ±
> > 692.047  ops/s
> > commonsFdf  yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt   12  4377.318 ± 209.050
> ops/s
> > javaDtf                  HH:mm:ss.SSS  thrpt   12  2515.950 ±  38.564
> ops/s
> > javaDtf     yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt   12  1794.764 ±  51.975
> ops/s
> > log4jFdf                 HH:mm:ss.SSS  thrpt   12  1032.089 ±  65.850
> ops/s
> > log4jFdf    yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt   12   696.700 ±  40.708
> ops/s
> >
> > The sources and results can be reached from this GitHub repository
> > <https://github.com/vy/date-time-format-benchmark> and the associated
> > GitHub Actions workflow runs
> > <https://github.com/vy/date-time-format-benchmark/runs/4008433552>,
> > respectively.
> >
> > The preliminary profiling points to
> > `FixedDateTime#millisSinceMidnight(long)` for the unexpected slowness of
> > `FixedDateTime`.
> >
> > Would anybody mind confirming that the measurements make sense and
> > `FixedDateTime` is... broken?
> >
>

Reply via email to