Skip to content

Parsing ISO-8601 21 to 67 times faster than java.time

In September 2026 I spent three days making a date parser faster. It already took less than a microsecond.

ITU is my library for the timestamps machines send each other, RFC 3339 and the ISO-8601 subset around it. It has existed since 2017.

After the three days, 1.16.0 parses a timestamp in 18 to 28 ns. java.time needs 542 to 577 ns for the same input on the same JDK. That is 21 to 30 times faster, and lenient parsing ends up 46 to 67 times faster. Nothing is allocated when you parse from a char[] or byte[].

Slowest input per operation, ns/op. Lower is better. parse, ITU 28 ns parse, JDK 577 ns parseLenient, ITU 17 ns parseLenient, JDK 788 ns formatSeconds, ITU 16 ns formatSeconds, JDK 100 ns formatNanos, ITU 33 ns formatNanos, JDK 115 ns parseDuration, ITU 52 ns parseDuration, JDK 247 ns

Measured with JMH on an i9-13900H laptop on JDK 25.0.4. The full report has every input with error bars.

Does it matter?

For one timestamp, no, it does not. Half a microsecond is nothing.

I tell people to measure before they optimise, and to stop when it is fast enough. By that rule I should have stopped years ago. I did not, since I like this kind of work, and I will not pretend the reason is better than that.

There is a real case too. A service that parses several timestamps per request, or a phone that parses thousands in one sync, pays that half microsecond every time. But that is the excuse and not the reason.

Throwing away the numbers

I have tuned this parser several times over the years. Each time I measured, kept what helped and threw away the numbers.

So I could not say what I had already tried. This time I kept a log of every attempt with its numbers, kept or not. It has a section called "Dead ends, do not retry without a new reason". Writing fields into the buffer as soon as they were parsed is in there. It looked obvious and gained nothing.

For someone who goes on about measuring, that took a long time to learn.

How it got fast

No single trick. The parser knows the format, so it reads digits at fixed positions instead of asking a formatter what comes next. An input of 19 characters or more takes a path with no per-field length checks. Dates are converted to day counts with Ben Joffe's algorithm. When formatting, digits are written two at a time from a table, straight into the caller's buffer.

Validation is the odd one. isValid on bad input is hundreds of times faster than the JDK, and it is not due to anything clever. The JDK builds an exception with a stack trace to tell you no. ITU returns false.

Where it loses

Formatting a duration is on par with the JDK, and slower for some inputs. It is in the report with the rest.

ITU also does less. No locales, no patterns, no calendars other than ISO. If you need those, this is not the library. And Instant.parse, the fastest built-in path, is in the benchmark too, so the comparison is not against the slowest thing I could find.

The benchmarks are in date-time-wars. Run them on your own hardware before you believe mine.