• lisael_@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    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)

  • M4mb0@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Try this one:

    results["now()"] = timeit.timeit(
        setup="import datetime; now=datetime.datetime.now", stmt="now()", number=number
    )
    
    • wil19558@fediverser.communick.devOPB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      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!

  • james_pic@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    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() or time.perf_counter(), since neither will be affected by NTP updates.

    • wil19558@fediverser.communick.devOPB
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 year ago

      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!