summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-06 11:17:07 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-06 11:17:07 +0300
commitf035108b0583ae02bbdf7a8713241c4d88e1e5bb (patch)
treee9b1c55516b432c538ba028082fc69a189c11ff3 /src
parent3b0e19ce80536aa98a86a60d8ea17da39f16057c (diff)
downloadchecksum-concurrency-f035108b0583ae02bbdf7a8713241c4d88e1e5bb.tar.gz
ref
Diffstat (limited to 'src')
-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
+ }
}
}