Skip to content

Commit ffeccb0

Browse files
committed
chore: add blob corruption benches
1 parent 1ad4b22 commit ffeccb0

4 files changed

Lines changed: 432 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ path = "src/lib.rs"
1111
rand = "0.8"
1212
image = "0.25"
1313
image-compare = "0.5.0"
14+
rayon = "1.10"
15+
memmap2 = "0.9"
1416

1517
[dev-dependencies]
1618
divan = { version = "4.0.2", package = "codspeed-divan-compat" }

benches/blob_corruption_checker.rs

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,95 @@
11
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};
33

44
fn main() {
55
divan::main();
66
}
77

88
#[divan::bench(sample_count = 3, sample_size = 5)]
9-
fn corruption_check(bencher: Bencher) {
9+
fn corruption_check_sequential(bencher: Bencher) {
1010
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(
1293
"reference.bin",
1394
"corrupted.bin",
1495
1024, // 1KB chunks

0 commit comments

Comments
 (0)