Last active
December 29, 2018 16:14
-
-
Save jan-matejka/34750945108e84e3e2cbc915ba56344f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
setup=""" | |
import logging | |
logging.basicConfig(filename='/dev/null') | |
depth = %d | |
loggers = [ | |
logging.getLogger(".".join(i * "a")) | |
for i in range(1, depth + 1) | |
] | |
l = loggers[-1] | |
""" | |
cut = "l.error('foo')" | |
for depth in range(1,10): | |
print("Timing depth %d" % depth) | |
timeit.main(["-s", setup % depth, cut]) | |
# Results: | |
# yac@beefcake % python bench.py | |
# Timing depth 1 | |
# 100000 loops, best of 3: 10.3 usec per loop | |
# Timing depth 2 | |
# 100000 loops, best of 3: 10.5 usec per loop | |
# Timing depth 3 | |
# 100000 loops, best of 3: 10.7 usec per loop | |
# Timing depth 4 | |
# 100000 loops, best of 3: 10.9 usec per loop | |
# Timing depth 5 | |
# 100000 loops, best of 3: 11.1 usec per loop | |
# Timing depth 6 | |
# 100000 loops, best of 3: 11.2 usec per loop | |
# Timing depth 7 | |
# 100000 loops, best of 3: 11.4 usec per loop | |
# Timing depth 8 | |
# 100000 loops, best of 3: 11.5 usec per loop | |
# Timing depth 9 | |
# 100000 loops, best of 3: 11.6 usec per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment