feat: cache IANA TLDs for faster lookups by salty-horse · Pull Request #390 · python-validators/validators

I wasn't sure what was meant by using dataclass, as this isn't a data-first class. I used a regular class, instead.

One thing that's obviously missing is tests. I'm not familiar with pytest, and don't know how to re-run the existing domain tests after running the new "load" function.

$ python -m timeit -s 'import validators' 'validators.domain("example.com", consider_tld=True)'
5000 loops, best of 5: 63.5 usec per loop
$ python -m timeit -s 'import validators; validators.load_iana_tlds_to_memory()' 'validators.domain("example.com", consider_tld=True)'
50000 loops, best of 5: 4.63 usec per loop

$ python -m timeit -s 'import validators' 'validators.domain("example.blabla", consider_tld=True)'
1000 loops, best of 5: 200 usec per loop
$ python -m timeit -s 'import validators; validators.load_iana_tlds_to_memory()' 'validators.domain("example.blabla", consider_tld=True)'
20000 loops, best of 5: 16.5 usec per loop