Skip to content

Commit 082532b

Browse files
committed
Fix benchmarks
1 parent 4618281 commit 082532b

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ edition = "2018"
1616

1717
[dependencies]
1818
crc-catalog = "2.1.0"
19+
20+
[dev-dependencies]
21+
criterion = { version = "0.3", features = ["html_reports"] }
22+
23+
[[bench]]
24+
name = "bench"
25+
harness = false

benches/bench.rs

+27-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crc::*;
22
use criterion::{criterion_group, criterion_main};
3-
use criterion::{Benchmark, Criterion, Throughput};
3+
use criterion::{Criterion, Throughput};
44

55
pub const BLUETOOTH: Crc<u8> = Crc::<u8>::new(&CRC_8_BLUETOOTH);
66
pub const X25: Crc<u16> = Crc::<u16>::new(&CRC_16_IBM_SDLC);
@@ -9,64 +9,54 @@ pub const GSM_40: Crc<u64> = Crc::<u64>::new(&CRC_40_GSM);
99
pub const ECMA: Crc<u64> = Crc::<u64>::new(&CRC_64_ECMA_182);
1010
pub const DARC: Crc<u128> = Crc::<u128>::new(&CRC_82_DARC);
1111

12+
const INPUT_SIZE: usize = 1_000_000;
13+
1214
fn crc8(c: &mut Criterion) {
1315
let mut digest = BLUETOOTH.digest();
14-
let bytes = vec![0u8; 1_000_000];
15-
c.bench(
16-
"crc8",
17-
Benchmark::new("crc8", move |b| b.iter(|| digest.update(&bytes)))
18-
.throughput(Throughput::Bytes(1_000_000)),
19-
);
16+
let bytes = vec![0u8; INPUT_SIZE];
17+
let mut group = c.benchmark_group("crc8");
18+
group.throughput(Throughput::Bytes(bytes.len() as u64))
19+
.bench_function("crc8", move |b| b.iter(|| digest.update(&bytes)));
2020
}
2121

2222
fn crc16(c: &mut Criterion) {
2323
let mut digest = X25.digest();
24-
let bytes = vec![0u8; 1_000_000];
25-
c.bench(
26-
"crc16",
27-
Benchmark::new("crc16", move |b| b.iter(|| digest.update(&bytes)))
28-
.throughput(Throughput::Bytes(1_000_000)),
29-
);
24+
let bytes = vec![0u8; INPUT_SIZE];
25+
let mut group = c.benchmark_group("crc16");
26+
group.throughput(Throughput::Bytes(bytes.len() as u64))
27+
.bench_function("crc16", move |b| b.iter(|| digest.update(&bytes)));
3028
}
3129

3230
fn crc32(c: &mut Criterion) {
3331
let mut digest = CASTAGNOLI.digest();
34-
let bytes = vec![0u8; 1_000_000];
35-
c.bench(
36-
"crc32",
37-
Benchmark::new("crc32", move |b| b.iter(|| digest.update(&bytes)))
38-
.throughput(Throughput::Bytes(1_000_000)),
39-
);
32+
let bytes = vec![0u8; INPUT_SIZE];
33+
let mut group = c.benchmark_group("crc32");
34+
group.throughput(Throughput::Bytes(bytes.len() as u64))
35+
.bench_function("crc32", move |b| b.iter(|| digest.update(&bytes)));
4036
}
4137

4238
fn crc40(c: &mut Criterion) {
4339
let mut digest = GSM_40.digest();
44-
let bytes = vec![0u8; 1_000_000];
45-
c.bench(
46-
"crc40",
47-
Benchmark::new("crc40", move |b| b.iter(|| digest.update(&bytes)))
48-
.throughput(Throughput::Bytes(1_000_000)),
49-
);
40+
let bytes = vec![0u8; INPUT_SIZE];
41+
let mut group = c.benchmark_group("crc40");
42+
group.throughput(Throughput::Bytes(bytes.len() as u64))
43+
.bench_function("crc40", move |b| b.iter(|| digest.update(&bytes)));
5044
}
5145

5246
fn crc64(c: &mut Criterion) {
5347
let mut digest = ECMA.digest();
54-
let bytes = vec![0u8; 1_000_000];
55-
c.bench(
56-
"crc64",
57-
Benchmark::new("crc64", move |b| b.iter(|| digest.update(&bytes)))
58-
.throughput(Throughput::Bytes(1_000_000)),
59-
);
48+
let bytes = vec![0u8; INPUT_SIZE];
49+
let mut group = c.benchmark_group("crc64");
50+
group.throughput(Throughput::Bytes(bytes.len() as u64))
51+
.bench_function("crc64", move |b| b.iter(|| digest.update(&bytes)));
6052
}
6153

6254
fn crc82(c: &mut Criterion) {
6355
let mut digest = ECMA.digest();
64-
let bytes = vec![0u8; 1_000_000];
65-
c.bench(
66-
"crc82",
67-
Benchmark::new("crc82", move |b| b.iter(|| digest.update(&bytes)))
68-
.throughput(Throughput::Bytes(1_000_000)),
69-
);
56+
let bytes = vec![0u8; INPUT_SIZE];
57+
let mut group = c.benchmark_group("crc82");
58+
group.throughput(Throughput::Bytes(bytes.len() as u64))
59+
.bench_function("crc82", move |b| b.iter(|| digest.update(&bytes)));
7060
}
7161

7262
criterion_group!(crc8_benches, crc8);

0 commit comments

Comments
 (0)