Successive calls to time.time() in Python sometimes yields the same result.

Paul's Avatar

Paul

28 Jun, 2019 08:53 PM

I have observed this a couple of times. These two commits are practically identical, yet one of the tests fails, because successive calls to ``time.time()`` yield the same result (tests a caching functionality).

https://ci.appveyor.com/project/paulmueller/dclab/builds/25624179/job/0p9t0skhl23l387i
https://ci.appveyor.com/project/paulmueller/dclab/builds/25624193/job/h7qp3o6mv6s4uwo7

  1. Support Staff 1 Posted by Owen McDonnell on 01 Jul, 2019 06:02 AM

    Owen McDonnell's Avatar

    How do you know they yield the same result?
    It doesn't look like thats what is being tested...

    assert t2-t1 > 10*(t1-t0)

  2. 2 Posted by Paul on 01 Jul, 2019 06:50 AM

    Paul's Avatar

    Because pytest says so...

    > assert t2-t1 > 10*(t1-t0)
    E assert (1561754079.254537 - 1561754079.254537) > (10 * (1561754079.254537 - 1561754079.254537))

    I doubt that the whole test could run through within less than a microsecond.

  3. Support Staff 3 Posted by Owen McDonnell on 01 Jul, 2019 09:08 AM

    Owen McDonnell's Avatar

    Ah, sorry, I see that now.
    And this only ever occurs on our build VMs (i.e. not on your local machine)?

  4. 4 Posted by Paul on 01 Jul, 2019 09:19 AM

    Paul's Avatar

    Yes, but locally I only use Linux...

  5. Support Staff 5 Posted by Owen McDonnell on 01 Jul, 2019 08:01 PM

    Owen McDonnell's Avatar

    Are you able to test on a windows machine, or give me instructions on how to test.

    Otherwise, we don't really have a way of determining that this is an issue that belongs to us.

    From the docs

    not all systems provide time with a better precision than 1 second

    Presumably that could be referring to windows machines, which is also supported by this response from SO

  6. 6 Posted by Paul on 01 Jul, 2019 09:23 PM

    Paul's Avatar

    Thanks, it probably is that timing accuracy issue. In the test, t2-t1 is about 5ms on my laptop, which is smaller than the 15ms mentioned in the post you linked.

    Testing is straight-forward:

    git clone https://github.com/ZELLMECHANIK-DRESDEN/dclab.git
    cd dclab
    pip install --upgrade pip
    pip install -e .[all]
    python setup.py test
    
  7. 7 Posted by Paul on 01 Jul, 2019 09:53 PM

    Paul's Avatar

    I have switched to time.perf_counter() for now. I think this one can be closed. Thanks!

  8. Support Staff 8 Posted by Owen McDonnell on 03 Jul, 2019 08:25 PM

    Owen McDonnell's Avatar

    Sorry, I still didn't get around to running the tests. But since you've found your own solution, i'll close. Feel free to open up again if you want more attention on it.

  9. Owen McDonnell closed this discussion on 03 Jul, 2019 08:25 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac