use std::ops::{BitAnd, BitOr, BitXor, Not}; use criterion::{criterion_group, criterion_main, Criterion}; use num_traits::NumCast; use arrow2::{ array::PrimitiveArray, compute::bitwise::*, types::NativeType, util::bench_util::create_primitive_array_with_seed, }; fn bench_or(lhs: &PrimitiveArray, rhs: &PrimitiveArray) where T: NativeType + BitOr + NumCast, { criterion::black_box(or(lhs, rhs)); } fn bench_xor(lhs: &PrimitiveArray, rhs: &PrimitiveArray) where T: NativeType + BitXor + NumCast, { criterion::black_box(xor(lhs, rhs)); } fn bench_and(lhs: &PrimitiveArray, rhs: &PrimitiveArray) where T: NativeType + BitAnd + NumCast, { criterion::black_box(and(lhs, rhs)); } fn bench_not(arr: &PrimitiveArray) where T: NativeType + Not + NumCast, { criterion::black_box(not(arr)); } fn add_benchmark(c: &mut Criterion) { (10..=20).step_by(2).for_each(|log2_size| { let size = 2usize.pow(log2_size); let arr_a = create_primitive_array_with_seed::(size, 0.0, 43); let arr_b = create_primitive_array_with_seed::(size, 0.0, 42); c.bench_function(&format!("or 2^{log2_size}"), |b| { b.iter(|| bench_or(&arr_a, &arr_b)) }); c.bench_function(&format!("xor 2^{log2_size}"), |b| { b.iter(|| bench_xor(&arr_a, &arr_b)) }); c.bench_function(&format!("and 2^{log2_size}"), |b| { b.iter(|| bench_and(&arr_a, &arr_b)) }); c.bench_function(&format!("not 2^{log2_size}"), |b| { b.iter(|| bench_not(&arr_a)) }); }); } criterion_group!(benches, add_benchmark); criterion_main!(benches);