summaryrefslogtreecommitdiff
path: root/morphlib
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
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')
-rw-r--r--morphlib/builder.py3
-rw-r--r--morphlib/stopwatch.py8
-rw-r--r--morphlib/stopwatch_tests.py4
3 files changed, 11 insertions, 4 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py
index 416216d3..31fc617f 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -93,11 +93,10 @@ class BinaryBlob(object):
'build-times': {}
}
for stage in self.build_watch.ticks.iterkeys():
- delta = self.build_watch.start_stop_delta(stage)
meta['build-times'][stage] = {
'start': '%s' % self.build_watch.start_time(stage),
'stop': '%s' % self.build_watch.stop_time(stage),
- 'delta': delta.total_seconds()
+ 'delta': self.build_watch.start_stop_seconds(stage)
}
self.write_cache_metadata(meta)
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))
diff --git a/morphlib/stopwatch_tests.py b/morphlib/stopwatch_tests.py
index 7441eac3..1a899f41 100644
--- a/morphlib/stopwatch_tests.py
+++ b/morphlib/stopwatch_tests.py
@@ -53,6 +53,6 @@ class StopwatchTests(unittest.TestCase):
our_delta = stop - start
watch_delta = self.stopwatch.start_stop_delta('start-stop')
-
- assert our_delta.total_seconds() > 0
self.assertEqual(our_delta, watch_delta)
+
+ assert self.stopwatch.start_stop_seconds('start-stop') > 0