-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmulti_pattern.rs
More file actions
74 lines (65 loc) · 2.3 KB
/
Copy pathmulti_pattern.rs
File metadata and controls
74 lines (65 loc) · 2.3 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
66
67
68
69
70
71
72
73
74
use chunk::chunk;
use criterion::{Criterion, Throughput, black_box, criterion_group, criterion_main};
fn bench_patterns_api(c: &mut Criterion) {
let text = std::fs::read("benches/data/enwik8").expect("Failed to load enwik8.");
let mut group = c.benchmark_group("patterns_api_enwik8");
group.throughput(Throughput::Bytes(text.len() as u64));
// Baseline: delimiters only (existing API)
group.bench_function("delimiters_only", |b| {
b.iter(|| {
let chunks: Vec<_> = chunk(black_box(&text))
.size(4096)
.delimiters(b"\n.?!")
.collect();
black_box(chunks)
})
});
// New API: delimiters + 3 CJK patterns (memmem path)
group.bench_function("delimiters_plus_3_patterns", |b| {
b.iter(|| {
let chunks: Vec<_> = chunk(black_box(&text))
.size(4096)
.delimiters(b"\n.?!")
.patterns(&["。", ",", "!"])
.collect();
black_box(chunks)
})
});
// New API: delimiters + 5 CJK patterns (Aho-Corasick path)
group.bench_function("delimiters_plus_5_patterns", |b| {
b.iter(|| {
let chunks: Vec<_> = chunk(black_box(&text))
.size(4096)
.delimiters(b"\n.?!")
.patterns(&["。", ",", "!", "?", ";"])
.collect();
black_box(chunks)
})
});
// New API: delimiters + 3 patterns + forward_fallback
group.bench_function("delimiters_3pat_fwd_fallback", |b| {
b.iter(|| {
let chunks: Vec<_> = chunk(black_box(&text))
.size(4096)
.delimiters(b"\n.?!")
.patterns(&["。", ",", "!"])
.forward_fallback()
.collect();
black_box(chunks)
})
});
// Patterns only (no delimiters)
group.bench_function("patterns_only_3", |b| {
b.iter(|| {
let chunks: Vec<_> = chunk(black_box(&text))
.size(4096)
.delimiters(b"")
.patterns(&["。", ",", "!"])
.collect();
black_box(chunks)
})
});
group.finish();
}
criterion_group!(benches, bench_patterns_api);
criterion_main!(benches);