aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2022-09-28 11:08:49 +0200
committerThéo de la Hogue2022-09-28 11:08:49 +0200
commit5f8660d960a47ff37282f192f8106da43da73bce (patch)
treeb4dd65c2e428968552e82a5456e8779a33482e52
parent57f683c89c09c29ef02aa5d442c2f1cb1f4ba90d (diff)
downloadargaze-5f8660d960a47ff37282f192f8106da43da73bce.zip
argaze-5f8660d960a47ff37282f192f8106da43da73bce.tar.gz
argaze-5f8660d960a47ff37282f192f8106da43da73bce.tar.bz2
argaze-5f8660d960a47ff37282f192f8106da43da73bce.tar.xz
Defining a TimeProbe class.
-rw-r--r--src/argaze/utils/MiscFeatures.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/argaze/utils/MiscFeatures.py b/src/argaze/utils/MiscFeatures.py
index 56a77bb..6fe51d5 100644
--- a/src/argaze/utils/MiscFeatures.py
+++ b/src/argaze/utils/MiscFeatures.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+import time
+
# Print iterations progress
def printProgressBar (iteration:int, total:int, prefix:str = '', suffix:str = '', decimals:int = 1, length:int = 100, fill:str = '█', printEnd:str = "\r"):
"""Print iterations progress.
@@ -42,4 +44,38 @@ class ExitSignalHandler():
signal.signal(getattr(signal, 'SIG'+sig), __on_exit_signal)
def status(self):
- return __exit_event.is_set() \ No newline at end of file
+ return __exit_event.is_set()
+
+# Assess temporal performance
+class TimeProbe():
+
+ def __init__(self):
+
+ self.start()
+
+ def start(self):
+
+ self.__last_time = time.perf_counter()
+ self.__lap_counter = 0
+ self.__elapsed_time = 0
+
+ def lap(self):
+
+ lap_time = time.perf_counter() - self.__last_time
+
+ self.__last_time = time.perf_counter()
+ self.__lap_counter += 1
+ self.__elapsed_time += lap_time
+
+ return lap_time, self.__lap_counter, self.__elapsed_time
+
+ def end(self):
+
+ self.__elapsed_time += time.perf_counter() - self.__last_time
+
+ return self.__elapsed_time
+
+ def restart(self):
+
+ self.start()
+