diff options
author | Zachary Sloan | 2013-02-28 23:59:12 +0000 |
---|---|---|
committer | Zachary Sloan | 2013-02-28 23:59:12 +0000 |
commit | f65a92de7c65e6528c5d01117c202401f7681ab0 (patch) | |
tree | fef1de2c5568ba43b5abe526f414f58ddf4108c9 /wqflask/utility | |
parent | fa4c4f116c37285d24edc9532bb223e18dfb1584 (diff) | |
download | genenetwork2-f65a92de7c65e6528c5d01117c202401f7681ab0.tar.gz |
Updated benchmark.py to aggregate run times when you run the
operation(s) multiple times
Diffstat (limited to 'wqflask/utility')
-rw-r--r-- | wqflask/utility/benchmark.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/wqflask/utility/benchmark.py b/wqflask/utility/benchmark.py index 0a6e422c..182187ae 100644 --- a/wqflask/utility/benchmark.py +++ b/wqflask/utility/benchmark.py @@ -7,6 +7,7 @@ import time class Bench(object): entries = collections.OrderedDict() + def __init__(self, name=None): self.name = name @@ -23,20 +24,22 @@ class Bench(object): else: name = "That" - time_took = time.time() - self.start_time - print(" %s took: %f seconds" % (name, (time_took))) + time_taken = time.time() - self.start_time + print(" %s took: %f seconds" % (name, (time_taken))) if self.name: - Bench.entries[self.name] = time_took + Bench.entries[self.name] = Bench.entries.get(self.name, 0) + time_taken + @classmethod def report(cls): - total_time = sum((time_took for time_took in cls.entries.itervalues())) + total_time = sum((time_taken for time_taken in cls.entries.itervalues())) print("\nTiming report\n") - for name, time_took in cls.entries.iteritems(): - percent = int(round((time_took/total_time) * 100)) - print("[{}%] {}: {}".format(percent, name, time_took)) + for name, time_taken in cls.entries.iteritems(): + percent = int(round((time_taken/total_time) * 100)) + print("[{}%] {}: {}".format(percent, name, time_taken)) print() - # Reset the entries after reporting + def reset(cls): + """Reset the entries""" cls.entries = collections.OrderedDict()
\ No newline at end of file |