From f107d705b5ee2aa7e996903073e9632abf259501 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 2 Oct 2018 17:03:49 +0300 Subject: Change: use nproc threads, fix chunking --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 11a6e80..4e25ddd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,6 +257,7 @@ dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index ba80db9..e7d723a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ walkdir = "2.2.5" serde = "1.0" serde_yaml = "0.8" rayon = "1.0.2" +num_cpus = "1.0" diff --git a/src/main.rs b/src/main.rs index a4501cf..109a6b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ extern crate crypto_hash; extern crate serde_yaml; extern crate walkdir; extern crate rayon; +extern crate num_cpus; use std::env; use std::io; @@ -17,7 +18,7 @@ type Map = BTreeMap<&'static str, String>; fn main() -> io::Result<()> { - let nproc = 4; + let nproc = num_cpus::get(); for dirname in env::args().skip(1) { summain(&dirname, nproc); } @@ -35,6 +36,7 @@ fn summain(dirname: &str, nproc: usize) { chunk.push(entry); if chunk.len() == nproc { process_chunk(&chunk); + chunk.clear(); } } -- cgit v1.2.1