|
1 | 1 | use divan::Bencher; |
2 | | -use eurorust_2025_workshop::blob_corruption_checker::find_corruptions_sequential; |
| 2 | +use eurorust_2025_workshop::blob_corruption_checker::{find_corruptions_parallel, find_corruptions_simd, find_corruptions_simd_parallel}; |
3 | 3 |
|
4 | 4 | fn main() { |
5 | 5 | divan::main(); |
6 | 6 | } |
7 | 7 |
|
8 | 8 | #[divan::bench(sample_count = 3, sample_size = 5)] |
9 | | -fn corruption_check(bencher: Bencher) { |
| 9 | +fn corruption_check_sequential(bencher: Bencher) { |
10 | 10 | bencher.bench_local(|| { |
11 | | - let corruptions = divan::black_box(find_corruptions_sequential( |
| 11 | + let corruptions = divan::black_box(find_corruptions_simd_parallel( |
| 12 | + "reference.bin", |
| 13 | + "corrupted.bin", |
| 14 | + 1024, // 1KB chunks |
| 15 | + )); |
| 16 | + |
| 17 | + assert_eq!(corruptions.len(), 50, "Should find 50 corruptions"); |
| 18 | + |
| 19 | + // All corruptions should be 1KB aligned |
| 20 | + for corruption in &corruptions { |
| 21 | + assert_eq!(corruption.offset % 1024, 0, "Corruption offset should be 1KB aligned"); |
| 22 | + assert_eq!(corruption.length % 1024, 0, "Corruption length should be multiple of 1KB"); |
| 23 | + } |
| 24 | + |
| 25 | + // Check specific corruptions |
| 26 | + assert_eq!(corruptions[0].offset, 14801920, "First corruption offset"); |
| 27 | + assert_eq!(corruptions[0].length, 2048, "First corruption length"); |
| 28 | + assert_eq!(corruptions[25].offset, 243891200, "Middle corruption offset"); |
| 29 | + assert_eq!(corruptions[25].length, 4096, "Middle corruption length"); |
| 30 | + assert_eq!(corruptions[49].offset, 507871232, "Last corruption offset"); |
| 31 | + assert_eq!(corruptions[49].length, 5120, "Last corruption length"); |
| 32 | + }); |
| 33 | +} |
| 34 | + |
| 35 | +#[divan::bench(sample_count = 3, sample_size = 5)] |
| 36 | +fn corruption_check_parallel(bencher: Bencher) { |
| 37 | + bencher.bench_local(|| { |
| 38 | + let corruptions = divan::black_box(find_corruptions_parallel( |
| 39 | + "reference.bin", |
| 40 | + "corrupted.bin", |
| 41 | + 1024, // 1KB chunks |
| 42 | + )); |
| 43 | + |
| 44 | + assert_eq!(corruptions.len(), 50, "Should find 50 corruptions"); |
| 45 | + |
| 46 | + // All corruptions should be 1KB aligned |
| 47 | + for corruption in &corruptions { |
| 48 | + assert_eq!(corruption.offset % 1024, 0, "Corruption offset should be 1KB aligned"); |
| 49 | + assert_eq!(corruption.length % 1024, 0, "Corruption length should be multiple of 1KB"); |
| 50 | + } |
| 51 | + |
| 52 | + // Check specific corruptions |
| 53 | + assert_eq!(corruptions[0].offset, 14801920, "First corruption offset"); |
| 54 | + assert_eq!(corruptions[0].length, 2048, "First corruption length"); |
| 55 | + assert_eq!(corruptions[25].offset, 243891200, "Middle corruption offset"); |
| 56 | + assert_eq!(corruptions[25].length, 4096, "Middle corruption length"); |
| 57 | + assert_eq!(corruptions[49].offset, 507871232, "Last corruption offset"); |
| 58 | + assert_eq!(corruptions[49].length, 5120, "Last corruption length"); |
| 59 | + }); |
| 60 | +} |
| 61 | + |
| 62 | +#[divan::bench(sample_count = 3, sample_size = 5)] |
| 63 | +fn corruption_check_simd(bencher: Bencher) { |
| 64 | + bencher.bench_local(|| { |
| 65 | + let corruptions = divan::black_box(find_corruptions_simd( |
| 66 | + "reference.bin", |
| 67 | + "corrupted.bin", |
| 68 | + 1024, // 1KB chunks |
| 69 | + )); |
| 70 | + |
| 71 | + assert_eq!(corruptions.len(), 50, "Should find 50 corruptions"); |
| 72 | + |
| 73 | + // All corruptions should be 1KB aligned |
| 74 | + for corruption in &corruptions { |
| 75 | + assert_eq!(corruption.offset % 1024, 0, "Corruption offset should be 1KB aligned"); |
| 76 | + assert_eq!(corruption.length % 1024, 0, "Corruption length should be multiple of 1KB"); |
| 77 | + } |
| 78 | + |
| 79 | + // Check specific corruptions |
| 80 | + assert_eq!(corruptions[0].offset, 14801920, "First corruption offset"); |
| 81 | + assert_eq!(corruptions[0].length, 2048, "First corruption length"); |
| 82 | + assert_eq!(corruptions[25].offset, 243891200, "Middle corruption offset"); |
| 83 | + assert_eq!(corruptions[25].length, 4096, "Middle corruption length"); |
| 84 | + assert_eq!(corruptions[49].offset, 507871232, "Last corruption offset"); |
| 85 | + assert_eq!(corruptions[49].length, 5120, "Last corruption length"); |
| 86 | + }); |
| 87 | +} |
| 88 | + |
| 89 | +#[divan::bench(sample_count = 3, sample_size = 5)] |
| 90 | +fn corruption_check_simd_parallel(bencher: Bencher) { |
| 91 | + bencher.bench_local(|| { |
| 92 | + let corruptions = divan::black_box(find_corruptions_simd_parallel( |
12 | 93 | "reference.bin", |
13 | 94 | "corrupted.bin", |
14 | 95 | 1024, // 1KB chunks |
|
0 commit comments