mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
dd: fix precision for display of total time spent
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
This commit is contained in:
parent
7c0063ae3e
commit
2f56536637
4 changed files with 65 additions and 24 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
use crate::common::util::*;
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{BufReader, Read, Write};
|
||||
use std::path::PathBuf;
|
||||
|
@ -261,7 +263,9 @@ fn test_final_stats_noxfer() {
|
|||
fn test_final_stats_unspec() {
|
||||
new_ucmd!()
|
||||
.run()
|
||||
.stderr_only("0+0 records in\n0+0 records out\n0 bytes copied, 0.0 s, 0.0 B/s\n")
|
||||
.stderr_contains("0+0 records in\n0+0 records out\n0 bytes copied, ")
|
||||
.stderr_matches(&Regex::new(r"\d\.\d+(e-\d\d)? s, ").unwrap())
|
||||
.stderr_contains("0.0 B/s")
|
||||
.success();
|
||||
}
|
||||
|
||||
|
@ -375,9 +379,11 @@ fn test_existing_file_truncated() {
|
|||
#[test]
|
||||
fn test_null_stats() {
|
||||
new_ucmd!()
|
||||
.args(&["if=null.txt"])
|
||||
.arg("if=null.txt")
|
||||
.run()
|
||||
.stderr_only("0+0 records in\n0+0 records out\n0 bytes copied, 0.0 s, 0.0 B/s\n")
|
||||
.stderr_contains("0+0 records in\n0+0 records out\n0 bytes copied, ")
|
||||
.stderr_matches(&Regex::new(r"\d\.\d+(e-\d\d)? s, ").unwrap())
|
||||
.stderr_contains("0.0 B/s")
|
||||
.success();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue