aboutsummaryrefslogtreecommitdiffstats
path: root/bench
diff options
context:
space:
mode:
Diffstat (limited to 'bench')
-rw-r--r--bench/Cargo.toml12
-rw-r--r--bench/src/main.rs76
2 files changed, 88 insertions, 0 deletions
diff --git a/bench/Cargo.toml b/bench/Cargo.toml
new file mode 100644
index 00000000..0dfb81d5
--- /dev/null
+++ b/bench/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "benches"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+nucleo = { version = "*", path = "../" }
+brunch = "0.5.0"
+fuzzy-matcher = "0.3.7"
+walkdir = "2"
diff --git a/bench/src/main.rs b/bench/src/main.rs
new file mode 100644
index 00000000..bc77b03d
--- /dev/null
+++ b/bench/src/main.rs
@@ -0,0 +1,76 @@
+use std::hint::black_box;
+use std::path::PathBuf;
+use std::process::Command;
+
+use brunch::{Bench, Benches};
+use fuzzy_matcher::FuzzyMatcher;
+use nucleo::{Utf32Str, Utf32String};
+
+fn bench_dir() -> PathBuf {
+ std::env::var_os("BENCHMARK_DIR")
+ .expect("the BENCHMARK_DIR must be set to the directory to traverse for the benchmark")
+ .into()
+}
+
+fn checkout_linux_if_needed() {
+ let linux_dir = bench_dir();
+ if !linux_dir.exists() {
+ println!("will git clone linux...");
+ let output = Command::new("git")
+ .arg("clone")
+ .arg("https://github.com/BurntSushi/linux.git")
+ .arg("--depth")
+ .arg("1")
+ .arg("--branch")
+ .arg("master")
+ .arg("--single-branch")
+ .arg(&linux_dir)
+ .stdout(std::process::Stdio::inherit())
+ .status()
+ .expect("failed to git clone linux");
+ println!("did git clone linux...{:?}", output);
+ }
+}
+
+fn main() {
+ checkout_linux_if_needed();
+ let dir = bench_dir();
+ let paths: (Vec<Utf32String>, Vec<String>) = walkdir::WalkDir::new(dir)
+ .into_iter()
+ .filter_map(|path| {
+ let dent = path.ok()?;
+ let path = dent.into_path().to_string_lossy().into_owned();
+ Some((path.as_str().into(), path))
+ })
+ .unzip();
+ let mut nucleo = nucleo::Matcher::new(nucleo::Config::DEFAULT.match_paths());
+ let skim = fuzzy_matcher::skim::SkimMatcherV2::default();
+
+ // TODO: unicode?
+ let needles = ["never_matches", "copying", "/doc/kernel", "//.h"];
+ // Announce that we've started.
+ ::std::eprint!("\x1b[1;38;5;199mStarting:\x1b[0m Running benchmark(s). Stand by!\n\n");
+ let mut benches = Benches::default();
+ // let mut scores = Vec::with_capacity(paths.0.len());
+ for needle in needles {
+ println!("running {needle:?}...");
+ benches.push(Bench::new(format!("nucleo {needle:?}")).run(|| {
+ // scores.clear();
+ // scores.extend(paths.0.iter().filter_map(|haystack| {
+ for haystack in &paths.0 {
+ black_box(
+ nucleo.fuzzy_match(haystack.slice(..), Utf32Str::Ascii(needle.as_bytes())),
+ );
+ }
+ // }));
+ // scores.sort_unstable();
+ }));
+ benches.push(Bench::new(format!("skim {needle:?}")).run(|| {
+ for haystack in &paths.1 {
+ let res = skim.fuzzy_match(haystack, needle);
+ let _ = black_box(res);
+ }
+ }));
+ }
+ benches.finish();
+}