aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2015-04-19 11:37:32 +0200
committerPjotr Prins2015-04-19 11:37:32 +0200
commite7cbe10d754e1e334746fc43a01e8b9fa3a666c0 (patch)
treecbeee2b2169ee51fc396b7a24dce229b6ef79e9c
parent240c2db33b70b7d10a6bdd18e043fc0aa6766715 (diff)
downloadgenenetwork2-e7cbe10d754e1e334746fc43a01e8b9fa3a666c0.tar.gz
pylmm: Copied benchmark (preparing for a module)
-rwxr-xr-xwqflask/wqflask/my_pylmm/pyLMM/benchmark.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/benchmark.py b/wqflask/wqflask/my_pylmm/pyLMM/benchmark.py
new file mode 100755
index 00000000..6c6c9f88
--- /dev/null
+++ b/wqflask/wqflask/my_pylmm/pyLMM/benchmark.py
@@ -0,0 +1,44 @@
+from __future__ import print_function, division, absolute_import
+
+import collections
+import inspect
+import time
+
+class Bench(object):
+ entries = collections.OrderedDict()
+
+ def __init__(self, name=None):
+ self.name = name
+
+ 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]))
+ 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.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()))
+ print("\nTiming report\n")
+ for name, time_taken in cls.entries.iteritems():
+ percent = int(round((time_taken/total_time) * 100))
+ print("[{}%] {}: {}".format(percent, name, time_taken))
+ print()
+
+ def reset(cls):
+ """Reset the entries"""
+ cls.entries = collections.OrderedDict()