Пример #1
0
    def test_remove_handler(self):
        w = Wryte(name=str(uuid.uuid4()))
        assert len(w.list_handlers()) == 1
        assert w.list_handlers() == ['_console']

        w.remove_handler('_console')
        assert len(w.list_handlers()) == 0
        assert w.list_handlers() == []
Пример #2
0
def _test_simple_message(count):
    w = Wryte(color=False, simple=False)
    w.remove_handler('_console')
    timing = []

    for _ in range(5):
        now = datetime.now()

        for _ in range(count):
            w.info('My Message')

        timing.append((datetime.now() - now).total_seconds() * 1000.0)

    return numpy.average(timing[1:])
Пример #3
0
 def test_remove_nonexisting_handler(self):
     w = Wryte(name=str(uuid.uuid4()))
     w.remove_handler('banana')
     assert len(w.list_handlers()) == 1
Пример #4
0
from wryte import Wryte
import timeit
import statistics

w = Wryte(color=False, simple=False)
w.remove_handler('_console')


def benchmark(code, repeat=20, number=10000):
    print('Benchmarking: `{}`'.format(code))
    results = timeit.repeat(code,
                            repeat=repeat,
                            number=number,
                            globals={'w': w})
    avg = sum(results) / len(results)
    p90 = sorted(results)[int(len(results) * 0.9)]
    print('20 iterations: ')
    print('\n'.join(map(str, results)))
    print('avg: {}, P90: {}'.format(statistics.mean(results), p90))


benchmark('w.info("test message")')
benchmark('w.info("test message with context", {"key": "value"})')
benchmark('w.log("info", "test messge")')
# without handlers, simple message
# 648e0c2: ~260ms
# 764dc31: ~260ms
#