|
2 | 2 | extern crate criterion;
|
3 | 3 | extern crate easy_reader;
|
4 | 4 |
|
5 |
| -use std::fs::File; |
6 | 5 | use criterion::Criterion;
|
7 | 6 | use easy_reader::EasyReader;
|
| 7 | +use std::fs::File; |
8 | 8 |
|
9 | 9 | fn criterion_benchmark(c: &mut Criterion) {
|
10 |
| - c.bench_function("build_index", |b| b.iter(|| { |
11 |
| - let file = File::open("resources/fatty_lipsum_lf").unwrap(); |
12 |
| - let mut reader = EasyReader::new(file).unwrap(); |
13 |
| - reader.build_index().unwrap(); |
14 |
| - })); |
| 10 | + c.bench_function("build_index", |b| { |
| 11 | + b.iter(|| { |
| 12 | + let file = File::open("resources/fatty_lipsum_lf").unwrap(); |
| 13 | + let mut reader = EasyReader::new(file).unwrap(); |
| 14 | + reader.build_index().unwrap(); |
| 15 | + }) |
| 16 | + }); |
15 | 17 |
|
16 | 18 | let file = File::open("resources/fatty_lipsum_lf").unwrap();
|
17 | 19 | let mut reader = EasyReader::new(file).unwrap();
|
18 | 20 | reader.build_index().unwrap();
|
19 |
| - c.bench_function( |
20 |
| - "Random lines [1000][index]", |
21 |
| - move |b| b.iter(|| { |
| 21 | + |
| 22 | + #[cfg(feature = "rand")] |
| 23 | + c.bench_function("Random lines [1000][index]", move |b| { |
| 24 | + b.iter(|| { |
22 | 25 | for _i in 0..1000 {
|
23 | 26 | reader.random_line().unwrap().unwrap();
|
24 | 27 | }
|
25 |
| - }), |
26 |
| - ); |
| 28 | + }) |
| 29 | + }); |
27 | 30 |
|
28 |
| - c.bench_function( |
29 |
| - "Random lines [1000][no_index]", |
30 |
| - |b| b.iter(|| { |
| 31 | + #[cfg(feature = "rand")] |
| 32 | + c.bench_function("Random lines [1000][no_index]", |b| { |
| 33 | + b.iter(|| { |
31 | 34 | let file = File::open("resources/fatty_lipsum_lf").unwrap();
|
32 | 35 | let mut reader = EasyReader::new(file).unwrap();
|
33 | 36 | for _i in 0..1000 {
|
34 | 37 | reader.random_line().unwrap().unwrap();
|
35 | 38 | }
|
36 |
| - }), |
37 |
| - ); |
| 39 | + }) |
| 40 | + }); |
38 | 41 |
|
39 | 42 | let file = File::open("resources/fatty_lipsum_lf").unwrap();
|
40 | 43 | let mut reader = EasyReader::new(file).unwrap();
|
41 | 44 | reader.build_index().unwrap();
|
42 |
| - c.bench_function( |
43 |
| - "Read backward [1000][index]", |
44 |
| - move |b| b.iter(|| { |
| 45 | + c.bench_function("Read backward [1000][index]", move |b| { |
| 46 | + b.iter(|| { |
45 | 47 | reader.eof();
|
46 | 48 | while let Ok(Some(_line)) = reader.prev_line() {}
|
47 |
| - }), |
48 |
| - ); |
| 49 | + }) |
| 50 | + }); |
49 | 51 |
|
50 |
| - c.bench_function( |
51 |
| - "Read backward [1000][no-index]", |
52 |
| - move |b| b.iter(|| { |
| 52 | + c.bench_function("Read backward [1000][no-index]", move |b| { |
| 53 | + b.iter(|| { |
53 | 54 | let file = File::open("resources/fatty_lipsum_lf").unwrap();
|
54 | 55 | let mut reader = EasyReader::new(file).unwrap();
|
55 | 56 | while let Ok(Some(_line)) = reader.prev_line() {}
|
56 |
| - }), |
57 |
| - ); |
| 57 | + }) |
| 58 | + }); |
58 | 59 |
|
59 | 60 | let file = File::open("resources/fatty_lipsum_lf").unwrap();
|
60 | 61 | let mut reader = EasyReader::new(file).unwrap();
|
61 | 62 | reader.build_index().unwrap();
|
62 |
| - c.bench_function( |
63 |
| - "Read forward [EasyReader][index]", |
64 |
| - move |b| b.iter(|| { |
| 63 | + c.bench_function("Read forward [EasyReader][index]", move |b| { |
| 64 | + b.iter(|| { |
65 | 65 | while let Ok(Some(_line)) = reader.next_line() {}
|
66 | 66 | reader.bof();
|
67 |
| - }), |
68 |
| - ); |
| 67 | + }) |
| 68 | + }); |
69 | 69 |
|
70 |
| - c.bench_function( |
71 |
| - "Read forward [EasyReader][no_index]", |
72 |
| - move |b| b.iter(|| { |
| 70 | + c.bench_function("Read forward [EasyReader][no_index]", move |b| { |
| 71 | + b.iter(|| { |
73 | 72 | let file = File::open("resources/fatty_lipsum_lf").unwrap();
|
74 | 73 | let mut reader = EasyReader::new(file).unwrap();
|
75 | 74 | while let Ok(Some(_line)) = reader.next_line() {}
|
76 |
| - }), |
77 |
| - ); |
| 75 | + }) |
| 76 | + }); |
78 | 77 | }
|
79 | 78 |
|
80 | 79 | criterion_group!(benches, criterion_benchmark);
|
|
0 commit comments