Skip to content

Commit

Permalink
fix benchmarks & update to 2021 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
fkohlgrueber committed May 19, 2022
1 parent 4618281 commit 86fae1d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ documentation = "https://docs.rs/crc"
description = "Rust implementation of CRC(16, 32, 64) with support of various standards"
keywords = ["crc", "crc16", "crc32", "crc64", "hash"]
categories = ["algorithms", "no-std"]
edition = "2018"
edition = "2021"

[dependencies]
crc-catalog = "2.1.0"

[dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"] }

[[bench]]
name = "bench"
harness = false
64 changes: 27 additions & 37 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crc::*;
use criterion::{criterion_group, criterion_main};
use criterion::{Benchmark, Criterion, Throughput};
use criterion::{Criterion, Throughput};

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

const INPUT_SIZE: usize = 1_000_000;

fn crc8(c: &mut Criterion) {
let mut digest = BLUETOOTH.digest();
let bytes = vec![0u8; 1_000_000];
c.bench(
"crc8",
Benchmark::new("crc8", move |b| b.iter(|| digest.update(&bytes)))
.throughput(Throughput::Bytes(1_000_000)),
);
let bytes = vec![0u8; INPUT_SIZE];
let mut group = c.benchmark_group("crc8");
group.throughput(Throughput::Bytes(bytes.len() as u64))
.bench_function("crc8", move |b| b.iter(|| digest.update(&bytes)));
}

fn crc16(c: &mut Criterion) {
let mut digest = X25.digest();
let bytes = vec![0u8; 1_000_000];
c.bench(
"crc16",
Benchmark::new("crc16", move |b| b.iter(|| digest.update(&bytes)))
.throughput(Throughput::Bytes(1_000_000)),
);
let bytes = vec![0u8; INPUT_SIZE];
let mut group = c.benchmark_group("crc16");
group.throughput(Throughput::Bytes(bytes.len() as u64))
.bench_function("crc16", move |b| b.iter(|| digest.update(&bytes)));
}

fn crc32(c: &mut Criterion) {
let mut digest = CASTAGNOLI.digest();
let bytes = vec![0u8; 1_000_000];
c.bench(
"crc32",
Benchmark::new("crc32", move |b| b.iter(|| digest.update(&bytes)))
.throughput(Throughput::Bytes(1_000_000)),
);
let bytes = vec![0u8; INPUT_SIZE];
let mut group = c.benchmark_group("crc32");
group.throughput(Throughput::Bytes(bytes.len() as u64))
.bench_function("crc32", move |b| b.iter(|| digest.update(&bytes)));
}

fn crc40(c: &mut Criterion) {
let mut digest = GSM_40.digest();
let bytes = vec![0u8; 1_000_000];
c.bench(
"crc40",
Benchmark::new("crc40", move |b| b.iter(|| digest.update(&bytes)))
.throughput(Throughput::Bytes(1_000_000)),
);
let bytes = vec![0u8; INPUT_SIZE];
let mut group = c.benchmark_group("crc40");
group.throughput(Throughput::Bytes(bytes.len() as u64))
.bench_function("crc40", move |b| b.iter(|| digest.update(&bytes)));
}

fn crc64(c: &mut Criterion) {
let mut digest = ECMA.digest();
let bytes = vec![0u8; 1_000_000];
c.bench(
"crc64",
Benchmark::new("crc64", move |b| b.iter(|| digest.update(&bytes)))
.throughput(Throughput::Bytes(1_000_000)),
);
let bytes = vec![0u8; INPUT_SIZE];
let mut group = c.benchmark_group("crc64");
group.throughput(Throughput::Bytes(bytes.len() as u64))
.bench_function("crc64", move |b| b.iter(|| digest.update(&bytes)));
}

fn crc82(c: &mut Criterion) {
let mut digest = ECMA.digest();
let bytes = vec![0u8; 1_000_000];
c.bench(
"crc82",
Benchmark::new("crc82", move |b| b.iter(|| digest.update(&bytes)))
.throughput(Throughput::Bytes(1_000_000)),
);
let bytes = vec![0u8; INPUT_SIZE];
let mut group = c.benchmark_group("crc82");
group.throughput(Throughput::Bytes(bytes.len() as u64))
.bench_function("crc82", move |b| b.iter(|| digest.update(&bytes)));
}

criterion_group!(crc8_benches, crc8);
Expand Down

0 comments on commit 86fae1d

Please sign in to comment.