| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
LGTM.
I hope that in future such optimization will not be needed. The lookup in sys.modules has the same cost as the lookup in globals(), but there is currently additional cost of checking that the module is not partially imported -- this is two additional attribute lookups (__spec__ and other). I am planning to optimize them out.
Sorry, something went wrong.
|
There have been some similar optimizations before, and it is suggested to start with gh-110761 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
It is faster to test for None than to go through the import logic to check sys.modules.
Baseline:
$ ./python.exe -m timeit -s 'from collections import Counter' -s 'c=Counter("abc")' 'c.most_common(1)' 500000 loops, best of 5: 481 nsec per loopPatched:
$ ./python.exe -m timeit -s 'from collections import Counter' -s 'c=Counter("abc")' 'c.most_common(1)' 500000 loops, best of 5: 400 nsec per loop