Skip to content

Commit 5934d78

Browse files
committed
Improve benchmarks
1 parent 7e7688a commit 5934d78

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

benches/benchmark.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crc_fast::checksum;
44
use crc_fast::CrcAlgorithm;
55
use criterion::*;
66
use rand::{rng, RngCore};
7+
use std::time::Duration;
78

89
pub const SIZES: &[(&str, i32); 2] = &[
910
("1 MiB", 1024 * 1024),
@@ -29,11 +30,12 @@ pub const SIZES: &[(&str, i32); 2] = &[
2930
];
3031

3132
// these are the most important algorithms in popular use, with forward/reflected coverage
32-
pub const CRC32_ALGORITHMS: &[CrcAlgorithm; 4] = &[
33-
CrcAlgorithm::Crc32Autosar, // reflected, internal
34-
CrcAlgorithm::Crc32Iscsi, // reflected, custom
35-
CrcAlgorithm::Crc32IsoHdlc, // reflected, custom
36-
CrcAlgorithm::Crc32Bzip2, // forward, internal
33+
pub const CRC32_ALGORITHMS: &[CrcAlgorithm; 3] = &[
34+
// benchmark both CRC-32/ISCSI and CRC-32/ISO-HDLC since they're special flowers with lots of
35+
// different acceleration targets.
36+
CrcAlgorithm::Crc32Iscsi, // reflected
37+
CrcAlgorithm::Crc32IsoHdlc, // reflected
38+
CrcAlgorithm::Crc32Bzip2, // forward
3739
];
3840

3941
// these are the most important algorithms in popular use, with forward/reflected coverage
@@ -78,13 +80,9 @@ fn bench_crc32(c: &mut Criterion) {
7880
let mut group = c.benchmark_group("CRC-32");
7981

8082
println!(
81-
"CRC-32/ISCSI implementation {}",
83+
"Acceleration target: {}",
8284
crc_fast::get_calculator_target(CrcAlgorithm::Crc32Iscsi)
8385
);
84-
println!(
85-
"CRC-32/ISO-HDLC implementation {}",
86-
crc_fast::get_calculator_target(CrcAlgorithm::Crc32IsoHdlc)
87-
);
8886

8987
for (size_name, size) in SIZES {
9088
let buf = create_aligned_data(&*random_data(*size));
@@ -101,6 +99,7 @@ fn bench_crc32(c: &mut Criterion) {
10199

102100
group.throughput(Throughput::Bytes(*size as u64));
103101
group.sample_size(1000);
102+
group.measurement_time(Duration::from_secs(30));
104103

105104
let bench_name = [alg_suffix.unwrap(), "(checksum)"].join(" ");
106105

@@ -128,6 +127,11 @@ fn bench_crc32(c: &mut Criterion) {
128127

129128
#[inline(always)]
130129
fn bench_crc64(c: &mut Criterion) {
130+
println!(
131+
"Acceleration target: {}",
132+
crc_fast::get_calculator_target(CrcAlgorithm::Crc64Nvme)
133+
);
134+
131135
let mut group = c.benchmark_group("CRC-64");
132136

133137
for (size_name, size) in SIZES {
@@ -145,6 +149,7 @@ fn bench_crc64(c: &mut Criterion) {
145149

146150
group.throughput(Throughput::Bytes(*size as u64));
147151
group.sample_size(1000);
152+
group.measurement_time(Duration::from_secs(30));
148153

149154
let bench_name = [alg_suffix.unwrap(), "(checksum)"].join(" ");
150155

@@ -170,6 +175,6 @@ fn bench_crc64(c: &mut Criterion) {
170175
}
171176
}
172177

173-
criterion_group!(benches, bench_crc64, bench_crc32);
178+
criterion_group!(benches, bench_crc32, bench_crc64);
174179

175180
criterion_main!(benches);

0 commit comments

Comments
 (0)