Skip to content

Commit a7dae2c

Browse files
committed
remove criterion
1 parent 64f283c commit a7dae2c

File tree

3 files changed

+63
-119
lines changed

3 files changed

+63
-119
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ syn = {version = "0.15.31", features = ["parsing", "full", "extra-traits"], opti
2020
starts-ends-with-caseless = {version = "0.2.1", optional = true}
2121

2222
[dev-dependencies]
23-
criterion = "0.2.5"
23+
bencher = "0.1.5"
2424
serde_json = "1.0"
2525

2626
[features]

README.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,15 @@ default-features = false
132132
Using static mechanisms makes your program faster. See my benchmark result below (Intel i7-6700HQ, ran on 2018/11/14):
133133

134134
```text
135-
include_str/include_str_no_static
136-
time: [8.3773 us 8.4061 us 8.4361 us]
137-
include_str/include_str_native_static
138-
time: [965.65 ns 969.47 ns 973.04 ns]
139-
include_str/include_str_lazy_static
140-
time: [955.93 ns 958.78 ns 961.88 ns]
141-
142-
include_bytes/include_bytes_no_static
143-
time: [7.7806 us 7.8056 us 7.8318 us]
144-
include_bytes/include_bytes_native_static
145-
time: [418.43 ns 420.12 ns 421.83 ns]
146-
include_bytes/include_bytes_lazy_static
147-
time: [413.43 ns 415.14 ns 417.37 ns]
148-
149-
include_array/include_array_no_static
150-
time: [30.125 us 30.285 us 30.445 us]
151-
include_array/include_array_native_static
152-
time: [38.510 ns 38.640 ns 38.786 ns]
153-
include_array/include_array_lazy_static
154-
time: [39.713 ns 39.863 ns 40.019 ns]
135+
test include_array_lazy_static ... bench: 43 ns/iter (+/- 3)
136+
test include_array_native_static ... bench: 46 ns/iter (+/- 4)
137+
test include_array_no_static ... bench: 29,714 ns/iter (+/- 1,156)
138+
test include_bytes_lazy_static ... bench: 382 ns/iter (+/- 63)
139+
test include_bytes_native_static ... bench: 380 ns/iter (+/- 30)
140+
test include_bytes_no_static ... bench: 9,076 ns/iter (+/- 1,224)
141+
test include_str_lazy_static ... bench: 932 ns/iter (+/- 103)
142+
test include_str_native_static ... bench: 937 ns/iter (+/- 25)
143+
test include_str_no_static ... bench: 10,135 ns/iter (+/- 1,634)
155144
```
156145

157146
When using the **release** profile, the performance of `lazy_static_include_*` is very close to `include_*`. That means you don't need to worry about the overhead, but just enjoy the faster compilation time.

benches/bench.rs

Lines changed: 53 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[macro_use]
2-
extern crate criterion;
2+
extern crate bencher;
33

44
#[macro_use]
55
extern crate lazy_static;
@@ -12,149 +12,104 @@ extern crate serde_json;
1212
use std::fs::File;
1313
use std::io::Read;
1414

15-
use criterion::{Criterion, Benchmark};
15+
use bencher::Bencher;
1616

17-
fn include_str_no_static(c: &mut Criterion) {
17+
fn include_str_no_static(bencher: &mut Bencher) {
1818
let path = concat!(concat!(env!("CARGO_MANIFEST_DIR"), "/", "data/benchmark.txt"));
1919

20-
c.bench(
21-
"include_str",
22-
Benchmark::new("include_str_no_static", move |b| {
23-
b.iter(|| {
24-
let mut f = File::open(&path).unwrap();
20+
bencher.iter(|| {
21+
let mut f = File::open(&path).unwrap();
2522

26-
let mut v = Vec::new();
23+
let mut v = Vec::new();
2724

28-
f.read_to_end(&mut v).unwrap();
25+
f.read_to_end(&mut v).unwrap();
2926

30-
let s = String::from_utf8(v).unwrap();
27+
let s = String::from_utf8(v).unwrap();
3128

32-
assert!(s.contains("figarofigaro"));
33-
});
34-
}),
35-
);
29+
assert!(s.contains("figarofigaro"));
30+
});
3631
}
3732

38-
fn include_str_native_static(c: &mut Criterion) {
33+
fn include_str_native_static(bencher: &mut Bencher) {
3934
let text = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", "data/benchmark.txt"));
4035

41-
c.bench(
42-
"include_str",
43-
Benchmark::new("include_str_native_static", move |b| {
44-
b.iter(|| {
45-
assert!(text.contains("figarofigaro"));
46-
});
47-
}),
48-
);
36+
bencher.iter(|| {
37+
assert!(text.contains("figarofigaro"));
38+
});
4939
}
5040

51-
fn include_str_lazy_static(c: &mut Criterion) {
41+
fn include_str_lazy_static(bencher: &mut Bencher) {
5242
lazy_static_include_str!(TEXT, "data/benchmark.txt");
5343

54-
c.bench(
55-
"include_str",
56-
Benchmark::new("include_str_lazy_static", move |b| {
57-
b.iter(|| {
58-
assert!((*TEXT).contains("figarofigaro"));
59-
});
60-
}),
61-
);
44+
bencher.iter(|| {
45+
assert!((*TEXT).contains("figarofigaro"));
46+
});
6247
}
6348

64-
fn include_bytes_no_static(c: &mut Criterion) {
49+
fn include_bytes_no_static(bencher: &mut Bencher) {
6550
let path = concat!(concat!(env!("CARGO_MANIFEST_DIR"), "/", "data/benchmark.txt"));
6651

67-
c.bench(
68-
"include_bytes",
69-
Benchmark::new("include_bytes_no_static", move |b| {
70-
b.iter(|| {
71-
let mut f = File::open(&path).unwrap();
52+
bencher.iter(|| {
53+
let mut f = File::open(&path).unwrap();
7254

73-
let mut v = Vec::new();
55+
let mut v = Vec::new();
7456

75-
f.read_to_end(&mut v).unwrap();
57+
f.read_to_end(&mut v).unwrap();
7658

77-
String::from_utf8(v).unwrap();
78-
});
79-
}),
80-
);
59+
String::from_utf8(v).unwrap();
60+
});
8161
}
8262

83-
fn include_bytes_native_static(c: &mut Criterion) {
63+
fn include_bytes_native_static(bencher: &mut Bencher) {
8464
let data = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/", "data/benchmark.txt"));
8565

86-
c.bench(
87-
"include_bytes",
88-
Benchmark::new("include_bytes_native_static", move |b| {
89-
b.iter(|| {
90-
String::from_utf8(data.to_vec()).unwrap();
91-
});
92-
}),
93-
);
66+
bencher.iter(|| {
67+
String::from_utf8(data.to_vec()).unwrap();
68+
});
9469
}
9570

96-
fn include_bytes_lazy_static(c: &mut Criterion) {
71+
fn include_bytes_lazy_static(bencher: &mut Bencher) {
9772
lazy_static_include_bytes!(DATA, "data/benchmark.txt");
9873

99-
c.bench(
100-
"include_bytes",
101-
Benchmark::new("include_bytes_lazy_static", move |b| {
102-
b.iter(|| {
103-
String::from_utf8((*DATA).to_vec()).unwrap();
104-
});
105-
}),
106-
);
74+
bencher.iter(|| {
75+
String::from_utf8((*DATA).to_vec()).unwrap();
76+
});
10777
}
10878

109-
fn include_array_no_static(c: &mut Criterion) {
79+
fn include_array_no_static(bencher: &mut Bencher) {
11080
let path = concat!(concat!(env!("CARGO_MANIFEST_DIR"), "/", "data/benchmark.txt"));
11181

112-
c.bench(
113-
"include_array",
114-
Benchmark::new("include_array_no_static", move |b| {
115-
b.iter(|| {
116-
let mut f = File::open(&path).unwrap();
82+
bencher.iter(|| {
83+
let mut f = File::open(&path).unwrap();
11784

118-
let mut v = Vec::new();
85+
let mut v = Vec::new();
11986

120-
f.read_to_end(&mut v).unwrap();
87+
f.read_to_end(&mut v).unwrap();
12188

122-
let array: Vec<&str> = serde_json::from_slice(&v).unwrap();
89+
let array: Vec<&str> = serde_json::from_slice(&v).unwrap();
12390

124-
assert!(array.binary_search(&"figarofigaro").is_ok());
125-
});
126-
}),
127-
);
91+
assert!(array.binary_search(&"figarofigaro").is_ok());
92+
});
12893
}
12994

130-
fn include_array_native_static(c: &mut Criterion) {
95+
fn include_array_native_static(bencher: &mut Bencher) {
13196
let array = include!(concat!(env!("CARGO_MANIFEST_DIR"), "/", "data/benchmark.txt"));
13297

133-
c.bench(
134-
"include_array",
135-
Benchmark::new("include_array_native_static", move |b| {
136-
b.iter(|| {
137-
assert!(array.binary_search(&"figarofigaro").is_ok());
138-
});
139-
}),
140-
);
98+
bencher.iter(|| {
99+
assert!(array.binary_search(&"figarofigaro").is_ok());
100+
});
141101
}
142102

143-
fn include_array_lazy_static(c: &mut Criterion) {
103+
fn include_array_lazy_static(bencher: &mut Bencher) {
144104
lazy_static_include_array!(ARRAY: [&'static str; 622], "data/benchmark.txt");
145105

146-
c.bench(
147-
"include_array",
148-
Benchmark::new("include_array_lazy_static", move |b| {
149-
b.iter(|| {
150-
assert!((*ARRAY).binary_search(&"figarofigaro").is_ok());
151-
});
152-
}),
153-
);
106+
bencher.iter(|| {
107+
assert!((*ARRAY).binary_search(&"figarofigaro").is_ok());
108+
});
154109
}
155110

156-
criterion_group!(include_str, include_str_no_static, include_str_native_static, include_str_lazy_static);
157-
criterion_group!(include_bytes, include_bytes_no_static, include_bytes_native_static, include_bytes_lazy_static);
158-
criterion_group!(include_array, include_array_no_static, include_array_native_static, include_array_lazy_static);
111+
benchmark_group!(include_str, include_str_no_static, include_str_native_static, include_str_lazy_static);
112+
benchmark_group!(include_bytes, include_bytes_no_static, include_bytes_native_static, include_bytes_lazy_static);
113+
benchmark_group!(include_array, include_array_no_static, include_array_native_static, include_array_lazy_static);
159114

160-
criterion_main!(include_str, include_bytes, include_array);
115+
benchmark_main!(include_str, include_bytes, include_array);

0 commit comments

Comments
 (0)