diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 26 |
2 files changed, 21 insertions, 6 deletions
@@ -7,4 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +rayon = "1.5.0" sha2 = "0.9.3" diff --git a/src/main.rs b/src/main.rs index 32102f2..c67d111 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,28 @@ use sha2::{Digest, Sha256}; +const N: usize = 10; +const SIZE: usize = 128 * 1024; + fn main() { - let blobs = Blobs::new(128 * 1024); - for blob in blobs.take(10) { - println!("{}", sha256(&blob)); + println!("sequential"); + for checksum in Blobs::new(SIZE, N).map(|x| sha256(&x)) { + println!("{}", checksum); } + + // println!("rayon"); + // for checksum in blobs.take(N).par_iter().map(|x| sha256(x)) { + // println!("{}", checksum); + // } } struct Blobs { size: usize, + n: usize, } impl Blobs { - fn new(size: usize) -> Self { - Self { size } + fn new(size: usize, n: usize) -> Self { + Self { size, n } } } @@ -21,7 +30,12 @@ impl Iterator for Blobs { type Item = Vec<u8>; fn next(&mut self) -> Option<Self::Item> { - Some(vec![0; self.size]) + if self.n > 0 { + self.n -= 1; + Some(vec![0; self.size]) + } else { + None + } } } |