-
Notifications
You must be signed in to change notification settings - Fork 751
improve datetime perf #1202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve datetime perf #1202
Conversation
looks like we are still running tests on 3.5, so we can't add inline typing or use f-string ... |
4cbaf1f
to
b67813d
Compare
also, why aware_now use time module instead of using datetime_.now.astimezone and combine it as datetime? |
I think we can also include a fast path for default datetime format |
Hey @trim21. Thank you for your work in improving Loguru's performance. I've done a few experiments and I think we can go even further. We do not need to repeatedly parse the tokens with the regex. We can build a formattable string associated with runtime formatting functions. See the diff here: 80f05fd Here are a $ python -m timeit -s "from loguru import logger;logger.remove();logger.add(lambda _: None, format='{time:YYYY-MM-DD HH:mm:ss.SSSSSS Z}');logger.info('Hello')" "for _ in range(10):logger.info('Hello')" Results: # master
500 loops, best of 5: 426 usec per loop
# trim21/datetime-perf
1000 loops, best of 5: 225 usec per loop
# Delgan/faster-datetime
2000 loops, best of 5: 160 usec per loop It's arguably an almost negligible improvement on what you've already done, but it pushes optimization further without adding much complexity. Do you mind if I merge this commit instead? Do you think it could be improved? |
Looks fine |
benchmark with simple
logger.info("hello {}", "b")
withos.devnull
sink, from 44s to 20sref: #1201