diff options
author | Ivan <ivan.demian2009@gmail.com> | 2023-01-27 12:21:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-27 12:21:48 +0000 |
commit | 63391419c11c1749a3d83dade19235a836c509f9 (patch) | |
tree | 5781c7fe6de7a61bb5936956e68e0582f03d7f6c /modules/timer.py | |
parent | f5d73b6a6646b51027c8e6f6c6154f21b58d6af2 (diff) | |
parent | 9beb794e0b0dc1a0f9e89d8e38bd789a8c608397 (diff) | |
download | stable-diffusion-webui-gfx803-63391419c11c1749a3d83dade19235a836c509f9.tar.gz stable-diffusion-webui-gfx803-63391419c11c1749a3d83dade19235a836c509f9.tar.bz2 stable-diffusion-webui-gfx803-63391419c11c1749a3d83dade19235a836c509f9.zip |
Merge branch 'AUTOMATIC1111:master' into master
Diffstat (limited to 'modules/timer.py')
-rw-r--r-- | modules/timer.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/timer.py b/modules/timer.py new file mode 100644 index 00000000..57a4f17a --- /dev/null +++ b/modules/timer.py @@ -0,0 +1,35 @@ +import time
+
+
+class Timer:
+ def __init__(self):
+ self.start = time.time()
+ self.records = {}
+ self.total = 0
+
+ def elapsed(self):
+ end = time.time()
+ res = end - self.start
+ self.start = end
+ return res
+
+ def record(self, category, extra_time=0):
+ e = self.elapsed()
+ if category not in self.records:
+ self.records[category] = 0
+
+ self.records[category] += e + extra_time
+ self.total += e + extra_time
+
+ def summary(self):
+ res = f"{self.total:.1f}s"
+
+ additions = [x for x in self.records.items() if x[1] >= 0.1]
+ if not additions:
+ return res
+
+ res += " ("
+ res += ", ".join([f"{category}: {time_taken:.1f}s" for category, time_taken in additions])
+ res += ")"
+
+ return res
|