#32892: Optimisation for parse_datetime by preferring datetime.fromisoformat for
well-formed values.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Keryn
Type: | Knight
Cleanup/optimization | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Keryn Knight):
Hey Hasan, absolutely no worries. I was surprised to be in a race (and
losing!) , but we're all here for the same reason :)
-------
For historical note, here's the equivalent timings for `parse_date` and
`parse_time` with similar (expected) improvements for the happy path:
Before, using the regex method only. Any and all variants are roughly the
same 3µs timing
{{{
parse_time('00:05:23+04:00') -> 3.56 µs ± 50 ns per loop (mean ± std.
dev. of 7 runs, 100000 loops each)
parse_time('00:05: ') -> 3 µs ± 41.3 ns per loop (mean ± std.
dev. of 7 runs, 100000 loops each)
parse_date('2000-01-01') -> 3.14 µs ± 28.1 ns per loop (mean ± std.
dev. of 7 runs, 100000 loops each)
}}}
After, using the regex method as a fallback and the builtin stricter
format by preference:
{{{
parse_time('00:05:23+04:00') -> 1.05 µs ± 2.65 ns per loop (mean ± std.
dev. of 7 runs, 1000000 loops each)
parse_time('00:05: ') -> 3.66 µs ± 15.2 ns per loop (mean ± std.
dev. of 7 runs, 100000 loops each)
parse_time('00:05:00') -> 987 ns ± 6.68 ns per loop (mean ± std.
dev. of 7 runs, 1000000 loops each)
parse_time('00:05:00.001') -> 1.03 µs ± 12.9 ns per loop (mean ± std.
dev. of 7 runs, 1000000 loops each)
parse_date('2000-01-01') -> 228 ns ± 2.89 ns per loop (mean ± std.
dev. of 7 runs, 1000000 loops each
}}}
Which handily suggests that the most expensive part of parsing the whole
iso string is the time+timezone handling, as you might expect.
--
Ticket URL: <https://code.djangoproject.com/ticket/32892#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.998c783bc815c03012bbea081e5f73ba%40djangoproject.com.