mirror of
https://github.com/sharkdp/fd
synced 2024-11-05 16:58:21 +00:00
Use N-1 search threads, where N = # cores
This commit is contained in:
parent
1268e982f6
commit
b4c8a8ba56
3 changed files with 20 additions and 4 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -6,6 +6,7 @@ dependencies = [
|
|||
"atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ignore 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -122,6 +123,14 @@ dependencies = [
|
|||
"libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "0.2.2"
|
||||
|
@ -249,6 +258,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915"
|
||||
"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
|
||||
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
|
||||
"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584"
|
||||
"checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b"
|
||||
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
|
||||
"checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7"
|
||||
|
|
|
@ -9,3 +9,4 @@ clap = "2.26.0"
|
|||
atty = "0.2"
|
||||
regex = "0.2"
|
||||
ignore = "0.2"
|
||||
num_cpus = "1.6.2"
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -4,6 +4,7 @@ extern crate ansi_term;
|
|||
extern crate atty;
|
||||
extern crate regex;
|
||||
extern crate ignore;
|
||||
extern crate num_cpus;
|
||||
|
||||
pub mod lscolors;
|
||||
pub mod fshelper;
|
||||
|
@ -67,7 +68,7 @@ struct FdOptions {
|
|||
max_depth: Option<usize>,
|
||||
|
||||
/// The number of threads to use.
|
||||
threads: Option<usize>,
|
||||
threads: usize,
|
||||
|
||||
/// Time to buffer results internally before streaming to the console. This is useful to
|
||||
/// provide a sorted output, in case the total execution time is shorter than
|
||||
|
@ -209,7 +210,7 @@ fn scan(root: &Path, pattern: Arc<Regex>, base: &Path, config: Arc<FdOptions>) {
|
|||
.git_exclude(config.read_ignore)
|
||||
.follow_links(config.follow_links)
|
||||
.max_depth(config.max_depth)
|
||||
.threads(config.threads.unwrap_or(0))
|
||||
.threads(config.threads)
|
||||
.build_parallel();
|
||||
|
||||
// Spawn the thread that receives all results through the channel.
|
||||
|
@ -433,8 +434,12 @@ fn main() {
|
|||
null_separator: matches.is_present("null_separator"),
|
||||
max_depth: matches.value_of("depth")
|
||||
.and_then(|n| usize::from_str_radix(n, 10).ok()),
|
||||
threads: matches.value_of("threads")
|
||||
.and_then(|n| usize::from_str_radix(n, 10).ok()),
|
||||
threads: std::cmp::max(
|
||||
matches.value_of("threads")
|
||||
.and_then(|n| usize::from_str_radix(n, 10).ok())
|
||||
.unwrap_or(num_cpus::get()),
|
||||
1
|
||||
),
|
||||
max_buffer_time: matches.value_of("max-buffer-time")
|
||||
.and_then(|n| u64::from_str_radix(n, 10).ok())
|
||||
.map(time::Duration::from_millis),
|
||||
|
|
Loading…
Reference in a new issue