WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
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
88 changes: 88 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions josh-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ keywords = ["git", "monorepo", "workflow", "scm"]
readme = "../README.md"
edition = "2024"

[[bench]]
name = "ultrawide"
harness = false

[dependencies]
backtrace = "0.3.76"
bitvec = "1.0.1"
Expand Down Expand Up @@ -37,5 +41,9 @@ sled = "0.34.7"
tracing = { workspace = true }
toml = { workspace = true }

[dev-dependencies]
rand = "0.9.2"
criterion2 = { version = "3.0.2" }

[features]
incubating = []
65 changes: 65 additions & 0 deletions josh-core/benches/ultrawide.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use criterion::{Criterion, criterion_group, criterion_main};
use itertools::Itertools;
use rand::Rng;
use rand::distr::{Alphabetic, Distribution};
use rand::rngs::ThreadRng;
use std::path::PathBuf;

const N_PATHS: usize = 30;

fn generate_paths() -> Vec<PathBuf> {
const PATH_COMPONENTS_MAX: usize = 10;
const PATH_COMPONENT_LEN: usize = 2;

// Create a single path component -- random lowercase characters,
// length of PATH_COMPONENT_LEN
fn make_path_component(rng: &mut ThreadRng) -> String {
(0..PATH_COMPONENT_LEN)
.map(|_| {
let ch = Alphabetic.sample(rng) as char;
ch.to_ascii_lowercase()
})
.collect()
}

// Create a single path -- anywhere from 1 to PATH_COMPONENTS_MAX components
fn make_path(rng: &mut ThreadRng) -> PathBuf {
let num_components = rng.random_range(1..=PATH_COMPONENTS_MAX);
let mut path = PathBuf::new();

for _ in 0..num_components {
path.push(make_path_component(rng))
}

path
}

let mut rng = rand::rng();

// Finally, create N_PATHS of random paths
(0..N_PATHS).map(|_| make_path(&mut rng)).collect()
}

fn ultrawide(c: &mut Criterion) {
c.bench_function("ultrawide_filter_parse", |b| {
b.iter_with_setup_wrapper(|runner| {
let filter = generate_paths()
.into_iter()
.map(|p| {
let p = p.display().to_string();
format!("::{p}/")
})
.join(",");

let filter = format!(":[{}]", filter);

runner.run(move || {
let filter = josh_core::filter::parse(&filter).expect("failed to parse");
std::hint::black_box(filter);
})
});
});
}

criterion_group!(benches, ultrawide);
criterion_main!(benches);
Loading