summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 20 insertions, 6 deletions
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
+ }
}
}