|
| 1 | +// MinIO Rust Library for Amazon S3 Compatible Cloud Storage |
| 2 | +// Copyright 2025 MinIO, Inc. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +use criterion::{Criterion, Throughput, criterion_group, criterion_main}; |
| 17 | +use minio::s3::utils::{ |
| 18 | + crc32_checksum, crc32c, crc64nvme_checksum, md5sum_hash, sha1_hash, sha256_checksum, |
| 19 | +}; |
| 20 | + |
| 21 | +fn bench_checksums(c: &mut Criterion) { |
| 22 | + let sizes = vec![ |
| 23 | + ("1KB", 1024), |
| 24 | + ("10KB", 10 * 1024), |
| 25 | + ("100KB", 100 * 1024), |
| 26 | + ("1MB", 1024 * 1024), |
| 27 | + ("10MB", 10 * 1024 * 1024), |
| 28 | + ]; |
| 29 | + |
| 30 | + for (name, size) in sizes { |
| 31 | + let data = vec![0u8; size]; |
| 32 | + |
| 33 | + let mut group = c.benchmark_group(format!("checksum_{}", name)); |
| 34 | + group.throughput(Throughput::Bytes(size as u64)); |
| 35 | + |
| 36 | + group.bench_function("CRC32", |b| b.iter(|| crc32_checksum(&data))); |
| 37 | + |
| 38 | + group.bench_function("CRC32C", |b| b.iter(|| crc32c(&data))); |
| 39 | + |
| 40 | + group.bench_function("CRC64NVME", |b| b.iter(|| crc64nvme_checksum(&data))); |
| 41 | + |
| 42 | + group.bench_function("MD5", |b| b.iter(|| md5sum_hash(&data))); |
| 43 | + |
| 44 | + group.bench_function("SHA1", |b| b.iter(|| sha1_hash(&data))); |
| 45 | + |
| 46 | + group.bench_function("SHA256", |b| b.iter(|| sha256_checksum(&data))); |
| 47 | + |
| 48 | + group.finish(); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +criterion_group!(benches, bench_checksums); |
| 53 | +criterion_main!(benches); |
0 commit comments