Skip to content

Instantly share code, notes, and snippets.

@LoboLofi
Created July 27, 2019 01:20
Show Gist options
  • Select an option

  • Save LoboLofi/76572f68da6b66ff2d860e2a286f8d50 to your computer and use it in GitHub Desktop.

Select an option

Save LoboLofi/76572f68da6b66ff2d860e2a286f8d50 to your computer and use it in GitHub Desktop.
Measure time and then show some metrics. The Non-Build-Profiler-hard-way
import time
import functools
class tmeasure(object):
dicTimes = {}
initTime = 0
glbTime = 0
def __init__(self):
initTime = 0
@staticmethod
def start():
tmeasure.initTime = time.time()
@staticmethod
def stop(Message):
elapsed = (time.time() - tmeasure.initTime)
# print(Message)
# print("\t", elapsed, " seconds")
if Message not in tmeasure.dicTimes.keys():
tmeasure.dicTimes[Message] = 0, 0
total, count = tmeasure.dicTimes[Message]
tmeasure.dicTimes[Message] = total + elapsed, count + 1
@staticmethod
def showTimes():
glbT = 0
for message in tmeasure.dicTimes.keys():
total, count = tmeasure.dicTimes[message]
glbT = glbT + total
for message in tmeasure.dicTimes.keys():
total, count = tmeasure.dicTimes[message]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment