Jim Paris
97bec3b1ee
row individually, when extracting data. Switch to using bisect module when doing the bisection, to lessen the chance of errors. Added syslog ability for timer module, for timing stuff deep inside the server. Make the chunked/non-chunked test just give a warning, rather than failing the tests, for debugging purposes. Alternate approach would be to disable "die on error" for the tests. git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb@10896 ddd99763-3ecb-0310-9145-efcb8ce7c51f
22 lines
512 B
Python
22 lines
512 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Simple timer to time a block of code, for optimization debugging
|
|
# use like:
|
|
# with nilmdb.Timer("flush"):
|
|
# foo.flush()
|
|
|
|
import contextlib
|
|
import time
|
|
|
|
@contextlib.contextmanager
|
|
def Timer(name = None, tosyslog = False):
|
|
start = time.time()
|
|
yield
|
|
elapsed = int((time.time() - start) * 1000)
|
|
msg = (name or 'elapsed') + ": " + str(elapsed) + " ms"
|
|
if tosyslog: # pragma: no cover
|
|
import syslog
|
|
syslog.syslog(msg)
|
|
else:
|
|
print msg
|