1use criterion::{Criterion, criterion_group, criterion_main};
2use project::{Entry, EntryKind, GitEntry, ProjectEntryId};
3use project_panel::par_sort_worktree_entries;
4use std::sync::Arc;
5use util::rel_path::RelPath;
6
7fn load_linux_repo_snapshot() -> Vec<GitEntry> {
8 let file = std::fs::read_to_string(
9 "/Users/hiro/Projects/zed/crates/project_panel/benches/linux_repo_snapshot.txt",
10 )
11 .expect("Failed to read file");
12 file.lines()
13 .filter_map(|line| {
14 let kind = match line.chars().next() {
15 Some('f') => EntryKind::File,
16 Some('d') => EntryKind::Dir,
17 _ => return None,
18 };
19
20 let entry = Entry {
21 kind,
22 path: Arc::from(RelPath::unix(&(line.trim_end()[2..])).unwrap()),
23 id: ProjectEntryId::default(),
24 size: 0,
25 inode: 0,
26 mtime: None,
27 canonical_path: None,
28 is_ignored: false,
29 is_always_included: false,
30 is_external: false,
31 is_private: false,
32 is_hidden: false,
33 char_bag: Default::default(),
34 is_fifo: false,
35 };
36 Some(GitEntry {
37 entry,
38 git_summary: Default::default(),
39 })
40 })
41 .collect()
42}
43fn criterion_benchmark(c: &mut Criterion) {
44 let snapshot = load_linux_repo_snapshot();
45 c.bench_function("Sort linux worktree snapshot", |b| {
46 b.iter_batched(
47 || snapshot.clone(),
48 |mut snapshot| par_sort_worktree_entries(&mut snapshot),
49 criterion::BatchSize::LargeInput,
50 );
51 });
52}
53
54criterion_group!(benches, criterion_benchmark);
55criterion_main!(benches);