def timedelta(self, start, end, start_key=min, end_key=max): """compute the difference between two sets of timestamps The default behavior is to use the earliest of the first and the latest of the second list, but this can be changed by passing a different Parameters ---------- start : one or more datetime objects (e.g. ar.submitted) end : one or more datetime objects (e.g. ar.received) start_key : callable Function to call on `start` to extract the relevant entry [default: min] end_key : callable Function to call on `end` to extract the relevant entry [default: max] Returns ------- dt : float The time elapsed (in seconds) between the two selected timestamps. """ if not isinstance(start, datetime): # handle single_result AsyncResults, where ar.stamp is single object, # not a list start = start_key(start) if not isinstance(end, datetime): # handle single_result AsyncResults, where ar.stamp is single object, # not a list end = end_key(end) return compare_datetimes(end, start).total_seconds()
def serial_time(self): """serial computation time of a parallel calculation Computed as the sum of (completed-started) of each task """ t = 0 for md in self._metadata: t += compare_datetimes(md['completed'], md['started']).total_seconds() return t
def elapsed(self): """elapsed time since initial submission""" if self.ready(): return self.wall_time now = submitted = utcnow() for msg_id in self.msg_ids: if msg_id in self._client.metadata: stamp = self._client.metadata[msg_id]['submitted'] if stamp and stamp < submitted: submitted = stamp return compare_datetimes(now, submitted).total_seconds()
def elapsed(self): """elapsed time since initial submission""" if self.ready(): return self.wall_time now = submitted = utcnow() self._parse_metadata_dates() for md in self._metadata: stamp = md["submitted"] if stamp and stamp < submitted: submitted = stamp return compare_datetimes(now, submitted).total_seconds()