Skip to content

Commit

Permalink
fmt: run source code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed Dec 31, 2020
1 parent 991bf0b commit f171953
Show file tree
Hide file tree
Showing 22 changed files with 610 additions and 462 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Not every application needs optimized logging, but where latency and performance

```
timestamp='2020-07-23T13:11:28.009804Z' logger='my-logger' level='debug' event='loading configuration' path='./config.yaml'
timestamp='2020-07-23T13:11:28.010137Z' logger='my-logger' level='info' event='starting application'
timestamp='2020-07-23T13:11:28.010137Z' logger='my-logger' level='info' event='starting application'
timestamp='2020-07-23T13:11:28.010158Z' logger='my-logger' level='warn' event='having too much fun' countdown=[3, 2, 1]
```

Expand All @@ -47,7 +47,7 @@ There are numerous sources discussion micro-optimizations in Python. This projec
does not implement them all, so there is room for improvement. Current optimization work has
leveraged:

* [`dis`](https://docs.python.org/3/library/dis.html): to disassemble python bytecode for analysis
* [`dis`](https://docs.python.org/3/library/dis.html): to disassemble python bytecode for analysis
* [`timeit`](https://docs.python.org/3/library/timeit.html): to measure execution time of code snippets

If you wish to contribute optimizations and use other libraries, tools, or sources, open a PR to add
Expand Down Expand Up @@ -88,4 +88,3 @@ processor and 16 GB 2400 MHz DDR4 memory.
While `containerlog` is intentionally feature-sparse, feature requests are welcome. Additionally,
if you can find any other ways to micro-optimize the codebase, pull requests are very much
appreciated.

42 changes: 23 additions & 19 deletions benchmarks/benchmark_containerlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@


class Custom:

def __init__(self):
self.val = 1

def __repr__(self):
return self.__str__()

def __str__(self):
return f'<Custom Object: {self.val}>'
return f"<Custom Object: {self.val}>"


MSG_BASIC = 'some message to log'
MSG_FORMATTED = 'a formatted message'
MSG_BASIC = "some message to log"
MSG_FORMATTED = "a formatted message"

SHORT_ARGS_SIMPLE = {'str': 'example'}
LONG_ARGS_SIMPLE = {'bool': True, 'str': 'example', 'int': 10, 'float': 0.131}
SHORT_ARGS_COMPLEX = {'obj': Custom()}
LONG_ARGS_COMPLEX = {'obj': Custom(), 'list': [Custom(), Custom()], 'dict': {'a': Custom(), 'b': Custom}, 'tuple': (Custom(), Custom())}
SHORT_ARGS_SIMPLE = {"str": "example"}
LONG_ARGS_SIMPLE = {"bool": True, "str": "example", "int": 10, "float": 0.131}
SHORT_ARGS_COMPLEX = {"obj": Custom()}
LONG_ARGS_COMPLEX = {
"obj": Custom(),
"list": [Custom(), Custom()],
"dict": {"a": Custom(), "b": Custom},
"tuple": (Custom(), Custom()),
}


def bench_baseline(loops, logger):
Expand Down Expand Up @@ -192,26 +196,26 @@ def bench_exception(loops, logger):


BENCHMARKS = {
'baseline': bench_baseline,
'silent': bench_silent,
'basic': bench_basic,
'short-simple': bench_short_simple,
'long-simple': bench_long_simple,
'short-complex': bench_short_complex,
'long-complex': bench_long_complex,
'exception': bench_exception,
"baseline": bench_baseline,
"silent": bench_silent,
"basic": bench_basic,
"short-simple": bench_short_simple,
"long-simple": bench_long_simple,
"short-complex": bench_short_complex,
"long-complex": bench_long_complex,
"exception": bench_exception,
}


if __name__ == '__main__':
if __name__ == "__main__":
runner = pyperf.Runner()
runner.metadata['description'] = 'Test the performance of containerlog.'
runner.metadata["description"] = "Test the performance of containerlog."

# Note: StringIO performance will impact the results
stream = io.StringIO()

# Setup the logger
log = containerlog.get_logger('bench-containerlog')
log = containerlog.get_logger("bench-containerlog")
log.level = containerlog.WARN
log.writeout = stream.write
log.writeerr = stream.write
Expand Down
46 changes: 25 additions & 21 deletions benchmarks/benchmark_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@


class Custom:

def __init__(self):
self.val = 1

def __repr__(self):
return self.__str__()

def __str__(self):
return f'<Custom Object: {self.val}>'
return f"<Custom Object: {self.val}>"


MSG_BASIC = 'some message to log'
MSG_FORMAT_SHORT_SIMPLE = 'a formatted message str=%s'
MSG_FORMAT_LONG_SIMPLE = 'a formatted message bool=%s str=%s int=%d float=%d'
MSG_FORMAT_SHORT_COMPLEX = 'a formatted message obj=%s'
MSG_FORMAT_LONG_COMPLEX = 'a formatted message obj=%s list=%s dict=%s tuple=%s'
MSG_BASIC = "some message to log"
MSG_FORMAT_SHORT_SIMPLE = "a formatted message str=%s"
MSG_FORMAT_LONG_SIMPLE = "a formatted message bool=%s str=%s int=%d float=%d"
MSG_FORMAT_SHORT_COMPLEX = "a formatted message obj=%s"
MSG_FORMAT_LONG_COMPLEX = "a formatted message obj=%s list=%s dict=%s tuple=%s"

SHORT_ARGS_SIMPLE = ['example']
LONG_ARGS_SIMPLE = [True, 'example', 10, 0.131]
SHORT_ARGS_SIMPLE = ["example"]
LONG_ARGS_SIMPLE = [True, "example", 10, 0.131]
SHORT_ARGS_COMPLEX = [Custom()]
LONG_ARGS_COMPLEX = [Custom(), [Custom(), Custom()], {'a': Custom(), 'b': Custom}, (Custom(), Custom())]
LONG_ARGS_COMPLEX = [
Custom(),
[Custom(), Custom()],
{"a": Custom(), "b": Custom},
(Custom(), Custom()),
]


def bench_baseline(loops, logger):
Expand Down Expand Up @@ -194,27 +198,27 @@ def bench_exception(loops, logger):


BENCHMARKS = {
'baseline': bench_baseline,
'silent': bench_silent,
'basic': bench_basic,
'short-simple': bench_short_simple,
'long-simple': bench_long_simple,
'short-complex': bench_short_complex,
'long-complex': bench_long_complex,
'exception': bench_exception,
"baseline": bench_baseline,
"silent": bench_silent,
"basic": bench_basic,
"short-simple": bench_short_simple,
"long-simple": bench_long_simple,
"short-complex": bench_short_complex,
"long-complex": bench_long_complex,
"exception": bench_exception,
}


if __name__ == '__main__':
if __name__ == "__main__":
runner = pyperf.Runner()
runner.metadata['description'] = 'Test the performance of Python standard logger.'
runner.metadata["description"] = "Test the performance of Python standard logger."

# Note: StringIO performance will impact the results
stream = io.StringIO()

# Setup the logger
handler = logging.StreamHandler(stream=stream)
std_logger = logging.getLogger('bench-std-logger')
std_logger = logging.getLogger("bench-std-logger")
std_logger.propagate = False
std_logger.addHandler(handler)
std_logger.setLevel(logging.WARNING)
Expand Down
46 changes: 25 additions & 21 deletions benchmarks/benchmark_std_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@


class Custom:

def __init__(self):
self.val = 1

def __repr__(self):
return self.__str__()

def __str__(self):
return f'<Custom Object: {self.val}>'
return f"<Custom Object: {self.val}>"


MSG_BASIC = 'some message to log'
MSG_FORMAT_SHORT_SIMPLE = 'a formatted message str=%s'
MSG_FORMAT_LONG_SIMPLE = 'a formatted message bool=%s str=%s int=%d float=%d'
MSG_FORMAT_SHORT_COMPLEX = 'a formatted message obj=%s'
MSG_FORMAT_LONG_COMPLEX = 'a formatted message obj=%s list=%s dict=%s tuple=%s'
MSG_BASIC = "some message to log"
MSG_FORMAT_SHORT_SIMPLE = "a formatted message str=%s"
MSG_FORMAT_LONG_SIMPLE = "a formatted message bool=%s str=%s int=%d float=%d"
MSG_FORMAT_SHORT_COMPLEX = "a formatted message obj=%s"
MSG_FORMAT_LONG_COMPLEX = "a formatted message obj=%s list=%s dict=%s tuple=%s"

SHORT_ARGS_SIMPLE = ['example']
LONG_ARGS_SIMPLE = [True, 'example', 10, 0.131]
SHORT_ARGS_SIMPLE = ["example"]
LONG_ARGS_SIMPLE = [True, "example", 10, 0.131]
SHORT_ARGS_COMPLEX = [Custom()]
LONG_ARGS_COMPLEX = [Custom(), [Custom(), Custom()], {'a': Custom(), 'b': Custom}, (Custom(), Custom())]
LONG_ARGS_COMPLEX = [
Custom(),
[Custom(), Custom()],
{"a": Custom(), "b": Custom},
(Custom(), Custom()),
]


def bench_baseline(loops, logger):
Expand Down Expand Up @@ -195,26 +199,26 @@ def bench_exception(loops, logger):


BENCHMARKS = {
'baseline': bench_baseline,
'silent': bench_silent,
'basic': bench_basic,
'short-simple': bench_short_simple,
'long-simple': bench_long_simple,
'short-complex': bench_short_complex,
'long-complex': bench_long_complex,
'exception': bench_exception,
"baseline": bench_baseline,
"silent": bench_silent,
"basic": bench_basic,
"short-simple": bench_short_simple,
"long-simple": bench_long_simple,
"short-complex": bench_short_complex,
"long-complex": bench_long_complex,
"exception": bench_exception,
}


if __name__ == '__main__':
if __name__ == "__main__":
runner = pyperf.Runner()
runner.metadata['description'] = 'Test the performance of Python standard logger.'
runner.metadata["description"] = "Test the performance of Python standard logger."

# Note: StringIO performance will impact the results
stream = io.StringIO()

# Setup the logger
proxy_log = containerlog.proxy.std.StdLoggerProxy('bench-std-proxy')
proxy_log = containerlog.proxy.std.StdLoggerProxy("bench-std-proxy")
proxy_log.level = containerlog.WARN
proxy_log.writeout = stream.write
proxy_log.writeerr = stream.write
Expand Down
Loading

0 comments on commit f171953

Please sign in to comment.