timeit() context manager to measure time for executing a block of code
This commit is contained in:
parent
2e2ccbb750
commit
0c5f41b2b3
1 changed files with 11 additions and 0 deletions
|
|
@ -11,7 +11,9 @@
|
|||
import signal
|
||||
import ctypes
|
||||
import unicodedata
|
||||
from contextlib import contextmanager
|
||||
from functools import lru_cache
|
||||
from time import monotonic
|
||||
|
||||
from PyQt5.QtGui import QFontMetrics
|
||||
|
||||
|
|
@ -97,3 +99,12 @@ def hangup():
|
|||
def is_simple_string(x):
|
||||
' We use the fact that python stores unicode strings with a 1-byte representation when possible '
|
||||
return sys.getsizeof(x) == base_size + len(x)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def timeit(name, do_timing=False):
|
||||
if do_timing:
|
||||
st = monotonic()
|
||||
yield
|
||||
if do_timing:
|
||||
print('Time for {}: {}'.format(name, monotonic() - st))
|
||||
|
|
|
|||
Loading…
Reference in a new issue