diff options
author | Pjotr Prins | 2016-06-21 09:10:40 +0000 |
---|---|---|
committer | Pjotr Prins | 2016-06-21 09:10:40 +0000 |
commit | 74ab1eff68fdad4183ce2a7490cfbc9ac1f4513f (patch) | |
tree | fc8733378c82d0b55fde284b39d4072692499bf2 /wqflask/utility/benchmark.py | |
parent | aa638a88e843657bb80f1db1e726b6135cefd11f (diff) | |
download | genenetwork2-74ab1eff68fdad4183ce2a7490cfbc9ac1f4513f.tar.gz |
Benchmarking: allow output select with LOG_BENCH
Diffstat (limited to 'wqflask/utility/benchmark.py')
-rw-r--r-- | wqflask/utility/benchmark.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/wqflask/utility/benchmark.py b/wqflask/utility/benchmark.py index d5b32703..887b3d88 100644 --- a/wqflask/utility/benchmark.py +++ b/wqflask/utility/benchmark.py @@ -3,34 +3,37 @@ from __future__ import print_function, division, absolute_import import collections import inspect import time +from utility.tools import LOG_BENCH class Bench(object): entries = collections.OrderedDict() - def __init__(self, name=None): + def __init__(self, name=None, write_output=True): self.name = name + self.write_output = write_output def __enter__(self): - if self.name: - print("Starting benchmark: %s" % (self.name)) - else: - print("Starting benchmark at: %s [%i]" % (inspect.stack()[1][3], inspect.stack()[1][2])) + if self.write_output: + if self.name: + print("Starting benchmark: %s" % (self.name)) + else: + print("Starting benchmark at: %s [%i]" % (inspect.stack()[1][3], inspect.stack()[1][2])) self.start_time = time.time() def __exit__(self, type, value, traceback): - if self.name: - name = self.name - else: - name = "That" - time_taken = time.time() - self.start_time - print(" %s took: %f seconds" % (name, (time_taken))) + if self.write_output: + if self.name: + name = self.name + else: + name = "That" + + print(" %s took: %f seconds" % (name, (time_taken))) if self.name: Bench.entries[self.name] = Bench.entries.get(self.name, 0) + time_taken - @classmethod def report(cls): total_time = sum((time_taken for time_taken in cls.entries.itervalues())) @@ -42,4 +45,4 @@ class Bench(object): def reset(cls): """Reset the entries""" - cls.entries = collections.OrderedDict()
\ No newline at end of file + cls.entries = collections.OrderedDict() |