luxon
luxon copied to clipboard
Perf: Add DateTime.buildFormatParser and DateTime.fromFormatParser
This is part of a series of PRs based on performance work we have done to improve a use-case involving parsing/formatting hundreds of thousands of dates where luxon was the bottleneck.
This allows constructing a parser for a locale/format and reusing it when parsing dates. Without this, DateTime.fromFormat constructs a new parser on every call. When parsing large amounts of date strings, this gets rather slow.
Benchmark Comparison (name | before | after | after/before
):
DateTime.fromFormat | 60,666 ±0.17% | 61,000 ±0.17% | ~
DateTime.fromFormat with zone | 26,687 ±0.18% | 26,688 ±0.21% | ~
DateTime.fromFormatParser | | 402,199 ±0.13%
DateTime.fromFormatParser with zone | | 45,206 ±0.22%
fromFormat vs. fromFormatParser | 60,666 ±0.17% | 402,199 ±0.13% | 6.63x
fromFormat vs fromFormatParser with zone | 26,687 ±0.18% | 45,206 | 1.69x
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: schleyfox / name: Ben Hughes (b56224e0a7f5cfa402750cfd3a96e911f8230157)
/easycla