Skip to content

Instantly share code, notes, and snippets.

@solomon-b
Created September 17, 2017 23:55
Show Gist options
  • Save solomon-b/7adfbde5365d41b74dbba6b20e5627c3 to your computer and use it in GitHub Desktop.
Save solomon-b/7adfbde5365d41b74dbba6b20e5627c3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import time
"""
Utility Functions and decorators for internal use
"""
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw:
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((te - ts) * 1000)
else:
print( '%r %2.2f ms' % \
(method.__name__, (te - ts) * 1000))
return result
return timed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment