I have observed some strange behaviour when trying to use Python's time/datetime modules to measure the performance of my mod. I wrote a class that looks like this:
And then I instantiate it at the start of the game, let the game run in autoplay (for up to 1h), and print the elapsed time at certain points.
The strange thing: the returned time is always a multiple of 2min 8s, which suspiciously also is 128 seconds. That is, I see 2:08, 4:16, 6:32, etc. but no result in between.
From the documentation I understand that subtracting two datetimes returns a timedelta, which should have a millisecond resolution (although I would even be happy with 1s), and nevertheless the same behavior occurs when using time() instead, which returns plain seconds since epoch. Always a multiple of 128.
Any idea what's going on? Am I not supposed to use these Python builtins for Civ4 and if not, is there a different/better way to time my code? Am I making a mistake? Is it related to autoplay?
I am confounded and grateful for any ideas.
Code:
from datetime import datetime
class Timer(object):
def __init__(self):
self.start = datetime.now()
def elapsed(self):
return datetime.now() - self.start
The strange thing: the returned time is always a multiple of 2min 8s, which suspiciously also is 128 seconds. That is, I see 2:08, 4:16, 6:32, etc. but no result in between.
From the documentation I understand that subtracting two datetimes returns a timedelta, which should have a millisecond resolution (although I would even be happy with 1s), and nevertheless the same behavior occurs when using time() instead, which returns plain seconds since epoch. Always a multiple of 128.
Any idea what's going on? Am I not supposed to use these Python builtins for Civ4 and if not, is there a different/better way to time my code? Am I making a mistake? Is it related to autoplay?
I am confounded and grateful for any ideas.