blob: c67d1117eebbd48b698cade3c183bc8f1b872c2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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<u8>;
fn next(&mut self) -> Option<Self::Item> {
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)
}
|