Delgan / loguru

Python logging made (stupidly) simple
MIT License
19.01k stars 681 forks source link

Benchmarks #667

Open NikitaMishin opened 2 years ago

NikitaMishin commented 2 years ago

Hi, Do u have benchmarks versus aiologger, standard logger and etc? Looking for fast logging and would like to know if loguru is fast enough

Delgan commented 2 years ago

No official benchmarks, but Loguru is not the best candidate for fast logging (yet).

It's currently slower than standard logging.

$ python -m timeit -n 10000 -s "import io,logging;logger=logging.getLogger('test');logger.addHandler(logging.StreamHandler(io.StringIO()))" "logger.warning('.')"
10000 loops, best of 5: 34.4 usec per loop
$ python -m timeit -n 10000 -s "from loguru import logger;import io;logger.remove();logger.add(io.StringIO(),format='{message}')" "logger.warning('.')"
10000 loops, best of 5: 43.1 usec per loop
matroscoe commented 2 years ago

Out of curiosity what are the major hurdles you see to it being the best candidate for fast logging? Adding a benchmark test suite could help evaluate change impacts moving forward. (Just my two cents)

Delgan commented 2 years ago

@matroscoe To achieve maximum performance, Loguru needs to be partially re-implemented using the C Python API. Before that, I'd like to release a v0.7.0 with some improvements and breaking changes. At this point I think the Loguru API will be finalized, so it will be easier to code it in C.

A benchmark suite would be interesting, maybe I'll add one. However, measuring performance is not a trivial matter, as the environment has a great influence on the measurements and can cause unreliable results.

lizheng2018CC commented 2 months ago

I find that this logger is much slower than built-in print function in Python. Therefore, I hope the C version of the logger is developed earlier.