Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
[package]
name = "find-files"
version = "0.1.5"
version = "0.1.6"
description = "Find Files (ff) utility recursively searches the files whose names match the specified RegExp pattern in the provided directory (defaults to the current directory if not provided)."
authors = ["Vishal Telangre <[email protected]>"]
license = "Unlicense OR MIT"
readme = "README.md"
repository = "https://github.com/vishaltelangre/ff"

[build-dependencies]
lazy_static = "1.1.0"
clap = "2.31.2"

[dependencies]
walkdir = "2"
ansi_term = "0.11"
Expand All @@ -18,12 +22,12 @@ num_cpus = "1.0"

[dependencies.clap]
version = "2.32"
default-features = false
features = [ "suggestions", "color" ]

[build-dependencies]
lazy_static = "1.1.0"

[[bin]]
name = "ff"
path = "src/main.rs"

[profile.release]
lto = true
codegen-units = 1
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,51 @@ Download the latest precompiled executable `ff` binary for your platform from th

If you're a Rust programmer, download and install `ff` command using `cargo install find-files`. To update to a newer version, use the `--force` flag.

# Benchmark Results

```
$ hyperfine \
--warmup 3 \
--export-markdown benchmark-results.md \
"find . -iregex '.*[0-9]\.jpg$'" \
"find . -iname '*[0-9].jpg'" \
"fd -HI '.*[0-9]\.jpg$'" \
"ff .*[0-9]\.jpg$"

Benchmark #1: find . -iregex '.*[0-9]\.jpg$'
Time (mean ± σ): 42.8 ms ± 5.5 ms [User: 11.7 ms, System: 30.1 ms]
Range (min … max): 31.2 ms … 56.9 ms 48 runs

Benchmark #2: find . -iname '*[0-9].jpg'
Time (mean ± σ): 60.8 ms ± 7.2 ms [User: 27.9 ms, System: 31.4 ms]
Range (min … max): 44.0 ms … 76.2 ms 37 runs

Benchmark #3: fd -HI '.*[0-9]\.jpg$'
Time (mean ± σ): 18.8 ms ± 5.3 ms [User: 14.9 ms, System: 19.9 ms]
Range (min … max): 11.2 ms … 41.6 ms 96 runs

Benchmark #4: ff .*[0-9]\.jpg$
Time (mean ± σ): 18.7 ms ± 4.6 ms [User: 15.7 ms, System: 22.5 ms]
Range (min … max): 11.7 ms … 30.4 ms 123 runs

Summary
'ff .*[0-9]\.jpg$' ran
1.00 ± 0.37 times faster than 'fd -HI '.*[0-9]\.jpg$''
2.29 ± 0.63 times faster than 'find . -iregex '.*[0-9]\.jpg$''
3.25 ± 0.88 times faster than 'find . -iname '*[0-9].jpg'
```

| Command | Mean [ms] | Min…Max [ms] |
|:---|---:|---:|
| `find . -iregex '.*[0-9]\.jpg$'` | 42.8 ± 5.5 | 31.2…56.9 |
| `find . -iname '*[0-9].jpg'` | 60.8 ± 7.2 | 44.0…76.2 |
| `fd -HI '.*[0-9]\.jpg$'` | 18.8 ± 5.3 | 11.2…41.6 |
| `ff .*[0-9]\.jpg$` | 18.7 ± 4.6 | 11.7…30.4 |

Table: *benchmark-results.md*

**NOTE:** Sometimes, `fd` is a bit faster than `ff` by approximately `1 ms` to `2 ms`.

## Usage

```
Expand Down Expand Up @@ -56,10 +101,10 @@ ARGS:
There are a tons of possibilities to search files using `ff`.
Following examples demonstrate just a tip of an iceberg.

- List paths of files recursively in the current working directory matching `article_` string.
- List paths of files recursively in the current working directory matching `article` string.

```
ff article_
ff article
```

- List files having `.png`, or `.PNG` extension.
Expand Down
2 changes: 1 addition & 1 deletion src/path_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<'a> PathPrinter<'a> {
Some(result) => {
let matched_str = &self.path[result.start()..result.end()];
let colored_match = Green.bold().paint(matched_str).to_string();
let path = &self.path.replace(matched_str, &colored_match);
let path = self.path.replace(matched_str, &colored_match);

println!("{}", path);
}
Expand Down
9 changes: 5 additions & 4 deletions src/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ impl<'a> Walker<'a> {
Ok(())
});

let working_dir_path = app::working_dir_path();

walker.run(|| {
let tx = tx.clone();
let reg_exp = self.args.reg_exp.clone();
let maybe_exclude_reg_exp = self.args.exclude_reg_exp.clone();
let working_dir_path = working_dir_path.clone();

Box::new(move |path_entry| {
if let Ok(entry) = path_entry {
let path = entry.path().display().to_string();
let path = truncate_working_dir_path(path);
let path = truncate_working_dir_path(path, &working_dir_path);

if is_match(&reg_exp, &maybe_exclude_reg_exp, &path) {
match tx.send(path) {
Expand Down Expand Up @@ -81,9 +84,7 @@ fn is_match(reg_exp: &Regex, maybe_exclude_reg_exp: &Option<Regex>, path: &str)
}
}

fn truncate_working_dir_path(path: String) -> String {
let working_dir_path = app::working_dir_path();

fn truncate_working_dir_path(path: String, working_dir_path: &str) -> String {
if path.contains(&working_dir_path) {
path.replace(&working_dir_path, ".")
} else {
Expand Down