1
DateTimeFormatter.BASIC_ISO_DATE.format(LocalDate localDate)

works extremely slow.

After collecting some statistic I have found that it takes 42836 ms per 119300 invocations.

I wonder why it is so slow and what is the best way to parse the same result faster?

Also, the same for the LocalDate#format - 27856ms per 71038 invocations

Oleksandr Riznyk
  • 758
  • 1
  • 8
  • 19
  • 4
    A third of a millisecond per invocation, does that count as extremely slow today? (Having grown up with computers with almost fewer clock cycles than that) – Ole V.V. Oct 09 '18 at 12:32
  • I have test and it took only under 500 milli seconds – yelliver Oct 09 '18 at 12:34
  • 1
    @yelliver i guess you were parsing not full date object – Oleksandr Riznyk Oct 09 '18 at 12:40
  • 3
    Can you share your benchmarking code? perhaps have a read of https://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java – Jo Peyper Oct 09 '18 at 12:44
  • 1
    First of all, you should more explicitly say that you're interested in parsing the dates, not formatting them. If you're interested in parsing dates in a specific format as fast as possible, it's best to write a JMH benchmark, then start implementing your own custom parser that will only work against that single format. Custom-written parsers tend to be faster because they do not need to care about correct locale / daytime saving / era shifts etc. What problem are you solving? ... https://stackoverflow.com/questions/10013998/fastest-way-to-parse-a-yyyymmdd-date-in-java – Petr Janeček Oct 09 '18 at 12:53
  • FWIW on my three year old Mac I formatted 100 000 `LocalDate`s using `BASIC_ISO_DATE` in 0.227 seconds. – Ole V.V. Oct 09 '18 at 13:08
  • Yup, I can also confirm that parsing is much faster then OP suggests. Perhaps @OleksandrRiznyk needs to show us his code as we cannot reproduce the problem. What Java are you using on which hardware? – Petr Janeček Oct 09 '18 at 13:12

0 Answers0