Skip to content

Commit 176e252

Browse files
committed
make rand an optional feature, upgrade rand -> 0.7, criterion -> 0.3, bump crate to 0.5.0
1 parent add1e55 commit 176e252

File tree

4 files changed

+488
-168
lines changed

4 files changed

+488
-168
lines changed

Cargo.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "easy_reader"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
authors = ["Michele Federici (@ps1dr3x) <[email protected]>"]
55
description = "Move forward, backward or randomly through the lines of huge files. Easily and fastly."
66
repository = "https://github.com/ps1dr3x/easy_reader"
@@ -10,11 +10,14 @@ readme = "README.md"
1010
edition = "2018"
1111

1212
[dependencies]
13-
rand = "~0.6"
13+
rand = { version = "~0.7", optional = true }
1414
fnv = "~1.0"
1515

16+
[features]
17+
default = ["rand"]
18+
1619
[dev-dependencies]
17-
criterion = "~0.2"
20+
criterion = "~0.3"
1821

1922
[[bench]]
2023
name = "benchmarks"

benches/benchmarks.rs

+35-36
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,78 @@
22
extern crate criterion;
33
extern crate easy_reader;
44

5-
use std::fs::File;
65
use criterion::Criterion;
76
use easy_reader::EasyReader;
7+
use std::fs::File;
88

99
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+
});
1517

1618
let file = File::open("resources/fatty_lipsum_lf").unwrap();
1719
let mut reader = EasyReader::new(file).unwrap();
1820
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(|| {
2225
for _i in 0..1000 {
2326
reader.random_line().unwrap().unwrap();
2427
}
25-
}),
26-
);
28+
})
29+
});
2730

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(|| {
3134
let file = File::open("resources/fatty_lipsum_lf").unwrap();
3235
let mut reader = EasyReader::new(file).unwrap();
3336
for _i in 0..1000 {
3437
reader.random_line().unwrap().unwrap();
3538
}
36-
}),
37-
);
39+
})
40+
});
3841

3942
let file = File::open("resources/fatty_lipsum_lf").unwrap();
4043
let mut reader = EasyReader::new(file).unwrap();
4144
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(|| {
4547
reader.eof();
4648
while let Ok(Some(_line)) = reader.prev_line() {}
47-
}),
48-
);
49+
})
50+
});
4951

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(|| {
5354
let file = File::open("resources/fatty_lipsum_lf").unwrap();
5455
let mut reader = EasyReader::new(file).unwrap();
5556
while let Ok(Some(_line)) = reader.prev_line() {}
56-
}),
57-
);
57+
})
58+
});
5859

5960
let file = File::open("resources/fatty_lipsum_lf").unwrap();
6061
let mut reader = EasyReader::new(file).unwrap();
6162
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(|| {
6565
while let Ok(Some(_line)) = reader.next_line() {}
6666
reader.bof();
67-
}),
68-
);
67+
})
68+
});
6969

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(|| {
7372
let file = File::open("resources/fatty_lipsum_lf").unwrap();
7473
let mut reader = EasyReader::new(file).unwrap();
7574
while let Ok(Some(_line)) = reader.next_line() {}
76-
}),
77-
);
75+
})
76+
});
7877
}
7978

8079
criterion_group!(benches, criterion_benchmark);

0 commit comments

Comments
 (0)