Skip to content

Commit

Permalink
v0.1.1 Released
Browse files Browse the repository at this point in the history
Maintenance:

- Improved README.
- Refactored code.
  • Loading branch information
LiosK committed Oct 10, 2021
1 parent 1dec806 commit ab644a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scru128-test"
version = "0.1.0"
version = "0.1.1"
authors = ["LiosK <contact@mail.liosk.net>"]
license = "Apache-2.0"
edition = "2018"
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ randomness field every second, and so on.
any-command-that-prints-identifiers-infinitely | scru128-test
```

## Build
## Installation

[Install Rust](https://www.rust-lang.org/tools/install) and build from source:

```bash
git clone https://github.com/scru128/gen_test.git
cd gen_test
cargo build --release

./target/release/scru128-test --help
cargo install --git https://github.com/scru128/gen_test.git
```

## License
Expand Down
39 changes: 16 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() {
// Triggered per STATS_INTERVAL seconds
if e.timestamp > st.ts_last_stats_print + STATS_INTERVAL {
if st.ts_last_stats_print > 0 {
st.print();
st.print().unwrap();
}
st.ts_last_stats_print = e.timestamp;
}
Expand All @@ -103,7 +103,7 @@ fn main() {
}

if st.n_processed > 0 {
st.print();
st.print().unwrap();
} else {
eprintln!("Error: no valid ID processed");
}
Expand Down Expand Up @@ -132,65 +132,58 @@ struct Status {
}

impl Status {
fn print(&self) {
fn print(&self) -> Result<(), io::Error> {
let time_elapsed = self.ts_last - self.ts_first;

let mut buf = io::BufWriter::new(io::stdout());
writeln!(buf).unwrap();
writeln!(buf, "{:<52} {:>8} {:>12}", "STAT", "EXPECTED", "ACTUAL").unwrap();
writeln!(buf)?;
writeln!(buf, "{:<52} {:>8} {:>12}", "STAT", "EXPECTED", "ACTUAL")?;
writeln!(
buf,
"{:<52} {:>8} {:>12.1}",
"Seconds from first input ID to last (sec)",
"NA",
time_elapsed as f64 / 1000.0
)
.unwrap();
)?;
writeln!(
buf,
"{:<52} {:>8} {:>12}",
"Number of valid IDs processed", "NA", self.n_processed
)
.unwrap();
)?;
writeln!(
buf,
"{:<52} {:>8} {:>12}",
"Number of invalid IDs skipped", 0, self.n_errors
)
.unwrap();
)?;
writeln!(
buf,
"{:<52} {:>8} {:>12.1}",
"Mean number of IDs per millisecond",
"NA",
self.n_processed as f64 / time_elapsed as f64
)
.unwrap();
)?;
writeln!(
buf,
"{:<52} {:>8} {:>12.3}",
"Mean interval of counter updates (msec)",
"~1",
self.sum_intervals_counter_update as f64 / self.n_counter_update as f64
)
.unwrap();
)?;
writeln!(
buf,
"{:<52} {:>8} {:>12.3}",
"Mean interval of per_sec_random updates (msec)",
"~1000",
self.sum_intervals_per_sec_random_update as f64 / self.n_per_sec_random_update as f64
)
.unwrap();
)?;

writeln!(
buf,
"{:<52} {:>8} {:>12}",
"1/0 ratio of each bit in counter at reset (min-max)",
"~0.500",
summarize_n_ones_by_bit(&self.n_ones_by_bit_counter, self.n_counter_update + 1)
)
.unwrap();
)?;
writeln!(
buf,
"{:<52} {:>8} {:>12}",
Expand All @@ -200,16 +193,16 @@ impl Status {
&self.n_ones_by_bit_per_sec_random,
self.n_per_sec_random_update + 1
)
)
.unwrap();
)?;
writeln!(
buf,
"{:<52} {:>8} {:>12}",
"1/0 ratio of each bit in per_gen_random (min-max)",
"~0.500",
summarize_n_ones_by_bit(&self.n_ones_by_bit_per_gen_random, self.n_processed)
)
.unwrap();
)?;

Ok(())
}
}

Expand Down

0 comments on commit ab644a5

Please sign in to comment.