Skip to content

Commit

Permalink
clean up dd_test example
Browse files Browse the repository at this point in the history
Use $NF and $(NF-10) instead of hard coded numbers
  • Loading branch information
tao-guo committed Mar 26, 2021
1 parent 6872746 commit c951d33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ let now = Instant::now();
let off = cnt * i;
let bandwidth = run_fun!(
sudo bash -c "dd if=$file of=/dev/null bs=$block_size skip=$off count=$cnt 2>&1"
| awk r"/copied/{print $10 $11}" | cut -d / -f1
| awk r#"/copied/{print $(NF-1) " " $NF}"#
)
.unwrap();
cmd_info!("thread $i bandwidth: ${bandwidth}/s");
cmd_info!("thread $i bandwidth: $bandwidth");
});
let total_bandwidth =
Byte::from_bytes((DATA_SIZE / now.elapsed().as_secs()) as u128).get_appropriate_unit(true);
Expand All @@ -67,10 +67,10 @@ Output will be like this:
Running `target/debug/examples/dd_test -b 4096 -f /dev/nvme0n1 -t 4`
Dropping caches at first
Running with thread_num: 4, block_size: 4096
thread 1 bandwidth: 286MB/s
thread 3 bandwidth: 269MB/s
thread 2 bandwidth: 267MB/s
thread 0 bandwidth: 265MB/s
thread 1 bandwidth: 286 MB/s
thread 3 bandwidth: 269 MB/s
thread 2 bandwidth: 267 MB/s
thread 0 bandwidth: 265 MB/s
Total bandwidth: 1.01 GiB/s
```

Expand Down
12 changes: 6 additions & 6 deletions examples/dd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// Running `target/debug/examples/dd_test -b 4096 -f /dev/nvme0n1 -t 4`
// Dropping caches at first
// Running with thread_num: 4, block_size: 4096
// thread 1 bandwidth: 286MB/s
// thread 3 bandwidth: 269MB/s
// thread 2 bandwidth: 267MB/s
// thread 0 bandwidth: 265MB/s
// thread 1 bandwidth: 286 MB/s
// thread 3 bandwidth: 269 MB/s
// thread 2 bandwidth: 267 MB/s
// thread 0 bandwidth: 265 MB/s
// Total bandwidth: 1.01 GiB/s
use byte_unit::Byte;
use cmd_lib::*;
Expand Down Expand Up @@ -51,10 +51,10 @@ fn main() -> CmdResult {
let off = cnt * i;
let bandwidth = run_fun!(
sudo bash -c "dd if=$file of=/dev/null bs=$block_size skip=$off count=$cnt 2>&1"
| awk r"/copied/{print $10 $11}" | cut -d / -f1
| awk r#"/copied/{print $(NF-1) " " $NF}"#
)
.unwrap();
cmd_info!("thread $i bandwidth: ${bandwidth}/s");
cmd_info!("thread $i bandwidth: $bandwidth");
});
let total_bandwidth =
Byte::from_bytes((DATA_SIZE / now.elapsed().as_secs()) as u128).get_appropriate_unit(true);
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
//! let off = cnt * i;
//! let bandwidth = run_fun!(
//! sudo bash -c "dd if=$file of=/dev/null bs=$block_size skip=$off count=$cnt 2>&1"
//! | awk r"/copied/{print $10 $11}" | cut -d / -f1
//! | awk r#"/copied/{print $(NF-1) " " $NF}"#
//! )
//! .unwrap();
//! cmd_info!("thread $i bandwidth: ${bandwidth}/s");
//! cmd_info!("thread $i bandwidth: $bandwidth");
//! });
//! let total_bandwidth =
//! Byte::from_bytes((DATA_SIZE / now.elapsed().as_secs()) as u128).get_appropriate_unit(true);
Expand All @@ -74,10 +74,10 @@
//! Running `target/debug/examples/dd_test -b 4096 -f /dev/nvme0n1 -t 4`
//! Dropping caches at first
//! Running with thread_num: 4, block_size: 4096
//! thread 1 bandwidth: 286MB/s
//! thread 3 bandwidth: 269MB/s
//! thread 2 bandwidth: 267MB/s
//! thread 0 bandwidth: 265MB/s
//! thread 1 bandwidth: 286 MB/s
//! thread 3 bandwidth: 269 MB/s
//! thread 2 bandwidth: 267 MB/s
//! thread 0 bandwidth: 265 MB/s
//! Total bandwidth: 1.01 GiB/s
//! ```
//!
Expand Down

0 comments on commit c951d33

Please sign in to comment.