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

dd: fix precision for display of total time spent #4498

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

jfinkels
Copy link
Collaborator

Improve the display of the total time spent transferring bytes so that the number of seconds is displayed using the %g format specifier as in printf. This matches the behavior of GNU dd.

Before this commit, the precision was always set to one digit after the decimal point. For example,

$ dd count=100000 if=/dev/zero of=/dev/null
100000+0 records in
100000+0 records out
51200000 bytes (51 MB, 49 MiB) copied, 0.2 s, 268.1 MB/s

After this commit, the precision increases dynamically as the duration decreases. For example,

$ dd count=100000 if=/dev/zero of=/dev/null
100000+0 records in
100000+0 records out
51200000 bytes (51 MB, 49 MiB) copied, 0.1019 s, 507 MB/s
$ dd count=1000 if=/dev/zero of=/dev/null
1000+0 records in
1000+0 records out
512000 bytes (512 kB, 500 KiB) copied, 0.002663 s, 256 MB/s
$ dd count=10 if=/dev/zero of=/dev/null
10+0 records in
10+0 records out
5120 bytes (5.1 kB, 5.0 KiB) copied, 0.000182 s, 5.1 MB/s

(Second attempt after #4169.)

Improve the display of the total time spent transferring bytes so that
the number of seconds is displayed using the `%g` format specifier as
in `printf`. This matches the behavior of GNU `dd`.

Before this commit, the precision was always set to one digit after
the decimal point. For example,

    $ dd count=100000 if=/dev/zero of=/dev/null
    100000+0 records in
    100000+0 records out
    51200000 bytes (51 MB, 49 MiB) copied, 0.2 s, 268.1 MB/s

After this commit, the precision increases dynamically as the duration
decreases. For example,

    $ dd count=100000 if=/dev/zero of=/dev/null
    100000+0 records in
    100000+0 records out
    51200000 bytes (51 MB, 49 MiB) copied, 0.1019 s, 507 MB/s
    $ dd count=1000 if=/dev/zero of=/dev/null
    1000+0 records in
    1000+0 records out
    512000 bytes (512 kB, 500 KiB) copied, 0.002663 s, 256 MB/s
    $ dd count=10 if=/dev/zero of=/dev/null
    10+0 records in
    10+0 records out
    5120 bytes (5.1 kB, 5.0 KiB) copied, 0.000182 s, 5.1 MB/s
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm rerunning the CI to make sure that passes, but it looks good so can be merged once that's done in my opinion.

@@ -692,6 +692,16 @@ impl CmdResult {
self
}

#[track_caller]
pub fn stderr_matches(&self, regex: &regex::Regex) -> &Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I thought we had this already :)

@tertsdiepraam tertsdiepraam merged commit b8f2f29 into uutils:main Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants