From cb7fe593bf3ee86346d9a1fed1d9befbf9f27dba Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Mon, 15 Jun 2020 18:00:02 +0100 Subject: [PATCH] Added debug timer --- openflexure_microscope/utilities.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/openflexure_microscope/utilities.py b/openflexure_microscope/utilities.py index 185478f6..3ca3f943 100644 --- a/openflexure_microscope/utilities.py +++ b/openflexure_microscope/utilities.py @@ -5,10 +5,22 @@ import base64 from uuid import UUID import numpy as np import logging +import time from collections import abc from functools import reduce from contextlib import contextmanager +class Timer(object): + def __init__(self, name): + self.name = name + self.start = None + self.end = None + def __enter__(self): + self.start = time.time() + def __exit__(self, type, value, traceback): + self.end = time.time() + logging.debug(f"{self.name} time: {self.end - self.start}") + def deserialise_array_b64(b64_string, dtype, shape): flat_arr = np.fromstring(base64.b64decode(b64_string), dtype)