-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathgungraun.rs
More file actions
65 lines (59 loc) · 1.68 KB
/
gungraun.rs
File metadata and controls
65 lines (59 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use gungraun::{library_benchmark, library_benchmark_group, main};
use std::fs;
use std::hint::black_box;
use skim::CaseMatching;
use skim::fuzzy_matcher::FuzzyMatcher;
use skim::fuzzy_matcher::arinae::ArinaeMatcher;
use skim::fuzzy_matcher::frizbee::FrizbeeMatcher;
use skim::prelude::SkimMatcherV2;
fn load_lines() -> Vec<String> {
let data = fs::read_to_string("benches/fixtures/1M.txt").expect("1M.txt missing");
data.lines().map(|l| l.to_string()).collect()
}
#[inline(always)]
fn bench_matcher(m: impl FuzzyMatcher, lines: Vec<String>) -> u64 {
let mut count = 0u64;
for line in &lines {
if m.fuzzy_indices(line, "test").is_some() {
count += 1;
}
}
count
}
#[library_benchmark]
fn skim_v2() -> u64 {
bench_matcher(SkimMatcherV2::default().smart_case(), black_box(load_lines()))
}
#[library_benchmark]
fn frizbee() -> u64 {
bench_matcher(
FrizbeeMatcher::default().case(CaseMatching::Smart).max_typos(Some(0)),
black_box(load_lines()),
)
}
#[library_benchmark]
fn frizbee_typos() -> u64 {
bench_matcher(
FrizbeeMatcher::default().case(CaseMatching::Smart).max_typos(Some(1)),
black_box(load_lines()),
)
}
#[library_benchmark]
fn arinae() -> u64 {
bench_matcher(
ArinaeMatcher::new(CaseMatching::Smart, false, false),
black_box(load_lines()),
)
}
#[library_benchmark]
fn arinae_typos() -> u64 {
bench_matcher(
ArinaeMatcher::new(CaseMatching::Smart, true, false),
black_box(load_lines()),
)
}
library_benchmark_group!(
name = benches,
benchmarks = [skim_v2, frizbee, frizbee_typos, arinae, arinae_typos]
);
main!(library_benchmark_groups = benches);