Skip to content

Commit 69519cf

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

4 files changed

Lines changed: 433 additions & 2 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: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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_sequential, 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(|| {
1111
let corruptions = divan::black_box(find_corruptions_sequential(
1212
"reference.bin",
@@ -31,3 +31,84 @@ fn corruption_check(bencher: Bencher) {
3131
assert_eq!(corruptions[49].length, 5120, "Last corruption length");
3232
});
3333
}
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(
93+
"reference.bin",
94+
"corrupted.bin",
95+
1024, // 1KB chunks
96+
));
97+
98+
assert_eq!(corruptions.len(), 50, "Should find 50 corruptions");
99+
100+
// All corruptions should be 1KB aligned
101+
for corruption in &corruptions {
102+
assert_eq!(corruption.offset % 1024, 0, "Corruption offset should be 1KB aligned");
103+
assert_eq!(corruption.length % 1024, 0, "Corruption length should be multiple of 1KB");
104+
}
105+
106+
// Check specific corruptions
107+
assert_eq!(corruptions[0].offset, 14801920, "First corruption offset");
108+
assert_eq!(corruptions[0].length, 2048, "First corruption length");
109+
assert_eq!(corruptions[25].offset, 243891200, "Middle corruption offset");
110+
assert_eq!(corruptions[25].length, 4096, "Middle corruption length");
111+
assert_eq!(corruptions[49].offset, 507871232, "Last corruption offset");
112+
assert_eq!(corruptions[49].length, 5120, "Last corruption length");
113+
});
114+
}

0 commit comments

Comments
 (0)