Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Instant/Duration math precision & associativity on Windows #57380

Merged
merged 4 commits into from
Jan 25, 2019

Commits on Jan 23, 2019

  1. Simplify units in Duration/Instant math on Windows

    Right now we do unit conversions between PerfCounter measurements
    and nanoseconds for every add/sub we do between Durations and Instants
    on Windows machines. This leads to goofy behavior, like this snippet
    failing:
    
    ```
    let now = Instant::now();
    let offset = Duration::from_millis(5);
    assert_eq!((now + offset) - now, (now - now) + offset);
    ```
    
    with precision problems like this:
    
    ```
    thread 'main' panicked at 'assertion failed: `(left == right)`
      left: `4.999914ms`,
     right: `5ms`', src\main.rs:6:5
    ```
    
    To fix it, this changeset does the unit conversion once, when we
    measure the clock, and all the subsequent math in u64 nanoseconds.
    
    It also adds an exact associativity test to the `sys/time.rs`
    test suite to make sure we don't regress on this in the future.
    bearcage committed Jan 23, 2019
    Configuration menu
    Copy the full SHA
    55dea0e View commit details
    Browse the repository at this point in the history
  2. Move Instant backing type to Duration

    Per review comments, this commit switches out the backing
    type for Instant on windows to a Duration. Tests all pass,
    and the code's a lot simpler (plus it should be portable now,
    with the exception of the QueryPerformanceWhatever functions).
    bearcage committed Jan 23, 2019
    Configuration menu
    Copy the full SHA
    0f566ec View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    41be93c View commit details
    Browse the repository at this point in the history

Commits on Jan 24, 2019

  1. Configuration menu
    Copy the full SHA
    14ce536 View commit details
    Browse the repository at this point in the history