- cross-posted to:
- python_dev@lemmy.pastwind.top
- cross-posted to:
- python_dev@lemmy.pastwind.top
Just a reminder : a time without a timezone info attached is about as useless as a text file without encoding info attached. (of course this doesn’t apply to your very special snow flake script, and a few other cases)
Try this one:
results["now()"] = timeit.timeit( setup="import datetime; now=datetime.datetime.now", stmt="now()", number=number )
Interesting! I’m compiling user suggestions: I’ll do a round 2 with comparison between Python versions, Ubuntu, WSL and Windows.
Thanks for the feedback!
If you’re using either of these functions to measure latency, you’re doing it wrong. You most likely want to be using
time.monotonic()
ortime.perf_counter()
, since neither will be affected by NTP updates.I’m measuring latency compared to other servers not under my control. More specifically, the time it takes me to receive a message with server-timestamped X, compared to the current time when I receive it. Using non-absolute counters like those you mention makes it impossible to compare timestamps.
In cases where you are comparing local times, I fully agree with you!
Wouldn’t it be better to use the epoch instead, and even better comparing epochs is computationally the easiest thing in the world.