use sha2::{Digest, Sha256}; const N: usize = 10; const SIZE: usize = 128 * 1024; fn main() { 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, n: usize) -> Self { Self { size, n } } } impl Iterator for Blobs { type Item = Vec; fn next(&mut self) -> Option { if self.n > 0 { self.n -= 1; Some(vec![0; self.size]) } else { None } } } fn sha256(data: &[u8]) -> String { let mut hasher = Sha256::new(); hasher.update(data); let hash = hasher.finalize(); format!("{:x}", hash) }