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

Improve Debug impl of time::Duration #50364

Merged
merged 3 commits into from
May 26, 2018

Commits on May 6, 2018

  1. Improve Debug impl of core::time::Duration

    Prior to this, Duration simply derived Debug. Since Duration doesn't
    implement `Display`, the only way to inspect its value is to use
    `Debug`. Unfortunately, the derived `Debug` impl is far from optimal
    for humans. In many cases, Durations are used for some quick'n'dirty
    benchmarking (or in general: measuring the time of some code). Correctly
    understanding the output of Duration's Debug impl is not easy (e.g.
    is "{ secs: 0, nanos: 968360102 }" or "{ secs: 0, nanos 98507324 }"
    shorter?).
    
    This commit replaces the derived impl with a manual one. It prints
    the duration as seconds (i.e. "3.1803s") if the duration is longer than
    a second, otherwise it prints it in either ms, µs or ns (depending on
    the duration's length). This already helps readability a lot and it
    never omits information that is stored.
    
    This `Debug` impl does *not* respect the following formatting parameters:
    
    - fill/align/padding: difficult to implement, probably not worth it
    - alternate # flag: not clear what this should do
    LukasKalbertodt committed May 6, 2018
    1 Configuration menu
    Copy the full SHA
    9eeb13f View commit details
    Browse the repository at this point in the history

Commits on May 16, 2018

  1. Implement rounding for Durations Debug output

    Rounding is done like for printing floating point numbers. If the
    first digit which isn't printed (due to the precision parameter) is
    larger than '4', the number is rounded up.
    LukasKalbertodt committed May 16, 2018
    Configuration menu
    Copy the full SHA
    2a28ac3 View commit details
    Browse the repository at this point in the history
  2. Fix Debug impl of Duration for precisions > 9

    Previously, the code would panic for high precision values. Now it
    has the same behavior as printing normal floating point values: if
    a high precision is specified, '0's are added.
    LukasKalbertodt committed May 16, 2018
    Configuration menu
    Copy the full SHA
    59e7114 View commit details
    Browse the repository at this point in the history