Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The problem for me with logging is that it's slow for production code:

Python 2.7.15 Linux (logging is 60x slower):

  [root@hbtest ~]# py -m timeit -s 'import logging' "logging.info('something happened')"
  1000000 loops, best of 3: 1.31 usec per loop

  [root@hbtest ~]# py -m timeit -s 'import sys; debug = False' "if debug: print >>sys.stderr, 'something happened'"
  10000000 loops, best of 3: 0.0216 usec per loop
Python 2.7.15 OSX (logging is 71x slower):

  $ py -m timeit -s 'import logging' "logging.info('something happened')"
  1000000 loops, best of 3: 0.925 usec per loop

  [jim@mbp hbrel]$ py -m timeit -s 'import sys; debug = False' "if debug: print >>sys.stderr, 'something happened'"
  100000000 loops, best of 3: 0.013 usec per loop
Python 3.6.8 Linux (logging is 99x slower):

  [root@hbtest ~]# python3 -m timeit -s 'import logging' "logging.info('something happened')"
  1000000 loops, best of 3: 1.62 usec per loop

  [root@hbtest ~]# python3 -m timeit -s 'import sys; debug = False' "if debug: print >>sys.stderr, 'something happened'"
  100000000 loops, best of 3: 0.0163 usec per loop
And, as usual, Python 3 is 25% slower than Python 2 for the logging case (but 2x faster for the noop if debug case). I hope the recent efforts to increase Python 3 performance are successful.


Microseconds are not important unless in a very tight loop. Avoid there and/or make a shortcut beforehand.


And we don't know why tus666 wants to print to stderr, nor what the issue was with Python, so this digression seems built on sand.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: