From f035108b0583ae02bbdf7a8713241c4d88e1e5bb Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 6 Apr 2021 11:17:07 +0300 Subject: ref --- Cargo.toml | 1 + src/main.rs | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 31e161f..a118afb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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; fn next(&mut self) -> Option { - Some(vec![0; self.size]) + if self.n > 0 { + self.n -= 1; + Some(vec![0; self.size]) + } else { + None + } } } -- cgit v1.2.1