#35467: Prefer urlsplit() over urlparse()
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Jake
Type: | Howard
Cleanup/optimization | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jake Howard):
* owner: nobody => Jake Howard
* status: new => assigned
Comment:
From some basic testing, it looks like this should have a nice
improvement:
{{{#!python
In [1]: import urllib.parse
In [2]: %timeit urllib.parse.urlparse("
https://example.com")
1.52 µs ± 37.9 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops
each)
In [3]: %timeit urllib.parse.urlsplit("
https://example.com")
258 ns ± 1.14 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops
each)
}}}
The difference stays about constant, even with longer URLs. The specifics
will obviously vary by hardware and Python version (the above is 3.12.3),
but ~6x improvement is definitely worthwhile.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35467#comment:3>