sorting.rs

 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                char_bag: Default::default(),
33                is_fifo: false,
34            };
35            Some(GitEntry {
36                entry,
37                git_summary: Default::default(),
38            })
39        })
40        .collect()
41}
42fn criterion_benchmark(c: &mut Criterion) {
43    let snapshot = load_linux_repo_snapshot();
44    c.bench_function("Sort linux worktree snapshot", |b| {
45        b.iter_batched(
46            || snapshot.clone(),
47            |mut snapshot| par_sort_worktree_entries(&mut snapshot),
48            criterion::BatchSize::LargeInput,
49        );
50    });
51}
52
53criterion_group!(benches, criterion_benchmark);
54criterion_main!(benches);