Skip to content

Commit 7807f41

Browse files
committed
add first xor benchmarks
1 parent 68712a0 commit 7807f41

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

timescale_vector/benches/distance.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ fn xor_unoptimized_u128(v1: &[u128], v2: &[u128]) -> usize {
273273
result
274274
}
275275

276+
fn xor_unoptimized_u128_fixed_size(v1: &[u128], v2: &[u128]) -> usize {
277+
let mut result = 0;
278+
for (b1, b2) in v1[..12].iter().zip(v2[..12].iter()) {
279+
result += (b1 ^ b2).count_ones() as usize;
280+
}
281+
result
282+
}
283+
276284
fn benchmark_distance_xor(c: &mut Criterion) {
277285
let r: Vec<bool> = (0..1536).map(|v| v as u64 % 2 == 0).collect();
278286
let l: Vec<bool> = (0..1536).map(|v| v as u64 % 3 == 0).collect();
@@ -294,13 +302,17 @@ fn benchmark_distance_xor(c: &mut Criterion) {
294302
b.iter(|| xor_unoptimized_u128(black_box(&r_u128), black_box(&l_u128)))
295303
});
296304

305+
assert!(r_u8.len() == 192);
306+
group.bench_function("xor unoptimized u8 fixed size", |b| {
307+
b.iter(|| xor_unoptimized_u8_fixed_size(black_box(&r_u8), black_box(&l_u8)))
308+
});
297309
assert!(r_u64.len() == 24);
298310
group.bench_function("xor unoptimized u64 fixed size", |b| {
299311
b.iter(|| xor_unoptimized_u64_fixed_size(black_box(&r_u64), black_box(&l_u64)))
300312
});
301-
assert!(r_u8.len() == 192);
302-
group.bench_function("xor unoptimized u8 fixed size", |b| {
303-
b.iter(|| xor_unoptimized_u8_fixed_size(black_box(&r_u8), black_box(&l_u8)))
313+
assert!(r_u128.len() == 12);
314+
group.bench_function("xor unoptimized u128 fixed size", |b| {
315+
b.iter(|| xor_unoptimized_u128_fixed_size(black_box(&r_u128), black_box(&l_u128)))
304316
});
305317
}
306318

0 commit comments

Comments
 (0)