Skip to content

Commit

Permalink
cylc#1751: speed up many cycle points example
Browse files Browse the repository at this point in the history
  • Loading branch information
benfitzpatrick committed Aug 20, 2018
1 parent 6ba43fd commit 4f6577e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/cylc/cycling/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
CYCLER_TYPE_ISO8601 = "iso8601"
CYCLER_TYPE_SORT_KEY_ISO8601 = "b"

MEMOIZE_LIMIT = 10000
MEMOIZE_LIMIT = 100000

DATE_TIME_FORMAT = "CCYYMMDDThhmm"
EXPANDED_DATE_TIME_FORMAT = "+XCCYYMMDDThhmm"
Expand Down Expand Up @@ -321,7 +321,7 @@ class ISO8601Sequence(SequenceBase):

TYPE = CYCLER_TYPE_ISO8601
TYPE_SORT_KEY = CYCLER_TYPE_SORT_KEY_ISO8601
_MAX_CACHED_POINTS = 100
_MAX_CACHED_POINTS = 1000

__slots__ = ('dep_section', 'context_start_point', 'context_end_point',
'offset', '_cached_first_point_values',
Expand Down
16 changes: 12 additions & 4 deletions lib/isodatetime/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,15 @@ def copy(self):
return TimeZone(hours=self.hours, minutes=self.minutes,
unknown=self.unknown)

def __cmp__(self, other):
if not isinstance(other, TimeZone):
raise TypeError(
"Invalid type for comparison: " +
"'%s' should be TimePoint." %
type(other).__name__
)
return cmp((self.hours, self.minutes), (other.hours, other.minutes))

def __str__(self):
if self.unknown:
return ""
Expand Down Expand Up @@ -1301,17 +1310,16 @@ def __cmp__(self, other):
raise TypeError(
"Cannot compare truncated to non-truncated " +
"TimePoint: %s, %s" % (self, other))
if self.get_props() == other.get_props():
return 0
if self.truncated:
for attribute in self.DATA_ATTRIBUTES:
other_attr = getattr(other, attribute)
self_attr = getattr(self, attribute)
if other_attr != self_attr:
return cmp(self_attr, other_attr)
return 0
other = other.copy()
other.set_time_zone(self.get_time_zone())
if other.get_time_zone() != self.get_time_zone():
other = other.copy()
other.set_time_zone(self.get_time_zone())
if self.get_is_calendar_date():
my_date = self.get_calendar_date()
other_date = other.get_calendar_date()
Expand Down

0 comments on commit 4f6577e

Please sign in to comment.