Skip to content

Commit

Permalink
add first xor benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
cevian committed Jan 24, 2024
1 parent 68712a0 commit 7807f41
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions timescale_vector/benches/distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ fn xor_unoptimized_u128(v1: &[u128], v2: &[u128]) -> usize {
result
}

fn xor_unoptimized_u128_fixed_size(v1: &[u128], v2: &[u128]) -> usize {
let mut result = 0;
for (b1, b2) in v1[..12].iter().zip(v2[..12].iter()) {
result += (b1 ^ b2).count_ones() as usize;
}
result
}

fn benchmark_distance_xor(c: &mut Criterion) {
let r: Vec<bool> = (0..1536).map(|v| v as u64 % 2 == 0).collect();
let l: Vec<bool> = (0..1536).map(|v| v as u64 % 3 == 0).collect();
Expand All @@ -294,13 +302,17 @@ fn benchmark_distance_xor(c: &mut Criterion) {
b.iter(|| xor_unoptimized_u128(black_box(&r_u128), black_box(&l_u128)))
});

assert!(r_u8.len() == 192);
group.bench_function("xor unoptimized u8 fixed size", |b| {
b.iter(|| xor_unoptimized_u8_fixed_size(black_box(&r_u8), black_box(&l_u8)))
});
assert!(r_u64.len() == 24);
group.bench_function("xor unoptimized u64 fixed size", |b| {
b.iter(|| xor_unoptimized_u64_fixed_size(black_box(&r_u64), black_box(&l_u64)))
});
assert!(r_u8.len() == 192);
group.bench_function("xor unoptimized u8 fixed size", |b| {
b.iter(|| xor_unoptimized_u8_fixed_size(black_box(&r_u8), black_box(&l_u8)))
assert!(r_u128.len() == 12);
group.bench_function("xor unoptimized u128 fixed size", |b| {
b.iter(|| xor_unoptimized_u128_fixed_size(black_box(&r_u128), black_box(&l_u128)))
});
}

Expand Down

0 comments on commit 7807f41

Please sign in to comment.