-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from lizhanhui/crc32c
Calculate CRC32C using SIMD acceleration
- Loading branch information
Showing
3 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crc::{Crc, CRC_32_ISCSI}; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use rand::{rngs::OsRng, RngCore}; | ||
|
||
pub const CASTAGNOLI: Crc<u32> = Crc::<u32>::new(&CRC_32_ISCSI); | ||
|
||
pub fn criterion_benchmark_4k(c: &mut Criterion) { | ||
let mut buffer = [0u8; 8192]; | ||
OsRng.fill_bytes(&mut buffer); | ||
|
||
let mut group = c.benchmark_group("8k"); | ||
group.throughput(criterion::Throughput::Bytes(8192)); | ||
group.bench_function("crc", |b| { | ||
b.iter(|| { | ||
let mut digest = CASTAGNOLI.digest(); | ||
digest.update(&buffer); | ||
black_box(digest.finalize()); | ||
}) | ||
}); | ||
|
||
group.bench_function("crc32c", |b| { | ||
b.iter(|| { | ||
black_box(crc32c::crc32c(&buffer)); | ||
}) | ||
}); | ||
} | ||
|
||
pub fn criterion_benchmark_1024k(c: &mut Criterion) { | ||
let mut buffer = [0u8; 1048576]; | ||
OsRng.fill_bytes(&mut buffer); | ||
|
||
let mut group = c.benchmark_group("1M"); | ||
group.throughput(criterion::Throughput::Bytes(1048576)); | ||
group.bench_function("crc", |b| { | ||
b.iter(|| { | ||
let mut digest = CASTAGNOLI.digest(); | ||
digest.update(&buffer); | ||
black_box(digest.finalize()); | ||
}) | ||
}); | ||
|
||
group.bench_function("crc32c", |b| { | ||
b.iter(|| { | ||
black_box(crc32c::crc32c(&buffer)); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark_4k, criterion_benchmark_1024k); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters