Created
August 20, 2013 14:04
-
-
Save asimihsan/6281904 to your computer and use it in GitHub Desktop.
First draft attempt at benchmarking logging vs. sys.stderr.write'ing. See: https://pypi.python.org/pypi/benchmark/
This file contains 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 logging | |
import sys | |
logger = logging.getLogger('simple_example') | |
logger.setLevel(logging.DEBUG) | |
ch = logging.StreamHandler() | |
ch.setLevel(logging.DEBUG) | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
ch.setFormatter(formatter) | |
logger.addHandler(ch) | |
verbosity = 2 | |
def debug(message): | |
if verbosity > 1: | |
sys.stderr.write(message) | |
import benchmark | |
class BenchmarkLogging(benchmark.Benchmark): | |
def test_debug(self): | |
logging.debug("i am a message") | |
class BenchmarkPrint(benchmark.Benchmark): | |
def test_debug(self): | |
debug("i am a message") | |
if __name__ == "__main__": | |
benchmark.main(format="markdown", numberFormat="%.4g", each=1000000) |
This file contains 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
Benchmark Report | |
================ | |
BenchmarkLogging | |
---------------- | |
name | rank | runs | mean | sd | timesBaseline | |
------|------|-------|-----------|----------|-------------- | |
debug | 1 | 1e+06 | 2.293e-06 | 1.15e-06 | 1.0 | |
BenchmarkPrint | |
-------------- | |
name | rank | runs | mean | sd | timesBaseline | |
------|------|-------|-----------|----------|-------------- | |
debug | 1 | 1e+06 | 1.362e-06 | 8.85e-07 | 1.0 | |
Each of the above 2000000 runs were run in random, non-consecutive order by | |
`benchmark` v0.1.5 (http://jspi.es/benchmark) with Python 2.7.3 | |
Linux-3.8.11-200.fc18.x86_64-x86_64 on 2013-08-20 14:01:51. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment