summaryrefslogtreecommitdiff
path: root/morphlib/stopwatch.py
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2011-12-08 16:21:03 +0100
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2011-12-08 16:21:03 +0100
commitfedaaf7f6c6e616edd51ebed6eb049e6babe9d94 (patch)
treee4ee7e98fe6a98c6625b07e67591a5ba038336b4 /morphlib/stopwatch.py
parent3248be791634da0052e56208881c66210e590403 (diff)
downloadmorph-fedaaf7f6c6e616edd51ebed6eb049e6babe9d94.tar.gz
Add Stopwatch.start_stop_seconds(), don't use timedelta.total_seconds().
This function is only available in Python >= 2.7. On http://docs.python.org/library/datetime.html#timedelta-objects it says total_seconds() is equal to (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 with true division enabled. We are using td.days * 24 * 3600 + td.seconds + operator.truediv(td.microseconds, 10**6) now in Stopwatch.start_stop_seconds(), which I find more readable.
Diffstat (limited to 'morphlib/stopwatch.py')
-rw-r--r--morphlib/stopwatch.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/morphlib/stopwatch.py b/morphlib/stopwatch.py
index bcdc9291..492738d5 100644
--- a/morphlib/stopwatch.py
+++ b/morphlib/stopwatch.py
@@ -14,6 +14,8 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import operator
+
from datetime import datetime
@@ -48,3 +50,9 @@ class Stopwatch(object):
def start_stop_delta(self, reference_object):
return (self.stop_time(reference_object) -
self.start_time(reference_object))
+
+ def start_stop_seconds(self, reference_object):
+ delta = self.start_stop_delta(reference_object)
+ return (delta.days * 24 * 3600 +
+ delta.seconds +
+ operator.truediv(delta.microseconds, 10**6))