|
1 |
| -use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 1 | +use criterion::{ |
| 2 | + black_box, criterion_group, criterion_main, |
| 3 | + measurement::{Measurement, WallTime}, |
| 4 | + Criterion, |
| 5 | +}; |
| 6 | +use criterion_linux_perf::{PerfMeasurement, PerfMode}; |
2 | 7 | use memmem::{Searcher, TwoWaySearcher};
|
3 | 8 | use std::{
|
4 | 9 | fs::File,
|
5 | 10 | io::{BufRead, BufReader},
|
6 | 11 | };
|
7 | 12 |
|
8 |
| -fn search_short_haystack(c: &mut Criterion) { |
| 13 | +fn search_short_haystack<M: Measurement>(c: &mut Criterion<M>) { |
9 | 14 | let mut needles = BufReader::new(File::open("../data/words.txt").unwrap())
|
10 | 15 | .lines()
|
11 | 16 | .map(Result::unwrap)
|
@@ -88,7 +93,7 @@ fn search_short_haystack(c: &mut Criterion) {
|
88 | 93 | group.finish();
|
89 | 94 | }
|
90 | 95 |
|
91 |
| -fn search_long_haystack(c: &mut Criterion) { |
| 96 | +fn search_long_haystack<M: Measurement>(c: &mut Criterion<M>) { |
92 | 97 | let haystack = include_str!("../../data/haystack");
|
93 | 98 |
|
94 | 99 | let needles = BufReader::new(File::open("../data/words.txt").unwrap())
|
@@ -161,5 +166,15 @@ fn search_long_haystack(c: &mut Criterion) {
|
161 | 166 | group.finish();
|
162 | 167 | }
|
163 | 168 |
|
164 |
| -criterion_group!(benches, search_short_haystack, search_long_haystack); |
165 |
| -criterion_main!(benches); |
| 169 | +criterion_group!( |
| 170 | + name = i386_wall_time; |
| 171 | + config = Criterion::default().with_measurement(WallTime); |
| 172 | + targets = search_short_haystack, search_long_haystack |
| 173 | +); |
| 174 | +criterion_group!( |
| 175 | + name = i386_perf_instructions; |
| 176 | + config = Criterion::default().with_measurement(PerfMeasurement::new(PerfMode::Instructions)); |
| 177 | + targets = search_short_haystack, search_long_haystack |
| 178 | +); |
| 179 | + |
| 180 | +criterion_main!(i386_wall_time, i386_perf_instructions); |
0 commit comments