diff options
author | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-05-18 19:01:32 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-05-18 19:01:32 +0300 |
commit | 09a4a7985bfac281ce41cc6bd19dc790af8bd979 (patch) | |
tree | 27c3c401a1410a6070b97b5fc304e01ada974e33 | |
parent | 3c1419b577883a226ebadcf79bb3ad68ec3ca4cf (diff) | |
download | checksums-09a4a7985bfac281ce41cc6bd19dc790af8bd979.tar.gz |
add a linear example without iterators
Sponsored-by: author
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 29de90f..8c9feec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,15 @@ fn main() { println!("{} ms", started.elapsed().as_millis()); println!(); + println!("linear iterator"); + let started = Instant::now(); + if let Err(e) = lineariter::checksums(&args.filenames) { + eprintln!("ERROR: {e}"); + std::process::exit(1); + } + println!("{} ms", started.elapsed().as_millis()); + println!(); + println!("rayon"); let started = Instant::now(); if let Err(e) = rayon::checksums(&args.filenames) { @@ -37,6 +46,21 @@ mod linear { use std::path::PathBuf; pub fn checksums(filenames: &[PathBuf]) -> anyhow::Result<()> { + let mut sums = vec![]; + for filename in filenames { + let sum = checksum(filename)?; + sums.push(sum); + } + print_checksums(&sums); + Ok(()) + } +} + +mod lineariter { + use checksums::*; + use std::path::PathBuf; + + pub fn checksums(filenames: &[PathBuf]) -> anyhow::Result<()> { let checksums: Result<Vec<FileChecksum>, std::io::Error> = filenames .iter() .map(|filename| checksum(filename)) |