diff --git a/arrow/benches/sort_kernel.rs b/arrow/benches/sort_kernel.rs index 8467b500f176..f9f5f24c15a6 100644 --- a/arrow/benches/sort_kernel.rs +++ b/arrow/benches/sort_kernel.rs @@ -27,12 +27,19 @@ use arrow::compute::kernels::sort::{lexsort, SortColumn}; use arrow::util::bench_util::*; use arrow::{array::*, datatypes::Float32Type}; -fn create_array(size: usize, with_nulls: bool) -> ArrayRef { +fn create_f32_array(size: usize, with_nulls: bool) -> ArrayRef { let null_density = if with_nulls { 0.5 } else { 0.0 }; let array = create_primitive_array::(size, null_density); Arc::new(array) } +fn create_bool_array(size: usize, with_nulls: bool) -> ArrayRef { + let null_density = if with_nulls { 0.5 } else { 0.0 }; + let true_density = 0.5; + let array = create_boolean_array(size, null_density, true_density); + Arc::new(array) +} + fn bench_sort(array_a: &ArrayRef, array_b: &ArrayRef, limit: Option) { let columns = vec![ SortColumn { @@ -49,58 +56,70 @@ fn bench_sort(array_a: &ArrayRef, array_b: &ArrayRef, limit: Option) { } fn add_benchmark(c: &mut Criterion) { - let arr_a = create_array(2u64.pow(10) as usize, false); - let arr_b = create_array(2u64.pow(10) as usize, false); + let arr_a = create_f32_array(2u64.pow(10) as usize, false); + let arr_b = create_f32_array(2u64.pow(10) as usize, false); c.bench_function("sort 2^10", |b| b.iter(|| bench_sort(&arr_a, &arr_b, None))); - let arr_a = create_array(2u64.pow(12) as usize, false); - let arr_b = create_array(2u64.pow(12) as usize, false); + let arr_a = create_f32_array(2u64.pow(12) as usize, false); + let arr_b = create_f32_array(2u64.pow(12) as usize, false); c.bench_function("sort 2^12", |b| b.iter(|| bench_sort(&arr_a, &arr_b, None))); - let arr_a = create_array(2u64.pow(10) as usize, true); - let arr_b = create_array(2u64.pow(10) as usize, true); + let arr_a = create_f32_array(2u64.pow(10) as usize, true); + let arr_b = create_f32_array(2u64.pow(10) as usize, true); c.bench_function("sort nulls 2^10", |b| { b.iter(|| bench_sort(&arr_a, &arr_b, None)) }); - let arr_a = create_array(2u64.pow(12) as usize, true); - let arr_b = create_array(2u64.pow(12) as usize, true); + let arr_a = create_f32_array(2u64.pow(12) as usize, true); + let arr_b = create_f32_array(2u64.pow(12) as usize, true); c.bench_function("sort nulls 2^12", |b| { b.iter(|| bench_sort(&arr_a, &arr_b, None)) }); + let arr_a = create_bool_array(2u64.pow(12) as usize, false); + let arr_b = create_bool_array(2u64.pow(12) as usize, false); + c.bench_function("bool sort 2^12", |b| { + b.iter(|| bench_sort(&arr_a, &arr_b, None)) + }); + + let arr_a = create_bool_array(2u64.pow(12) as usize, true); + let arr_b = create_bool_array(2u64.pow(12) as usize, true); + c.bench_function("bool sort nulls 2^12", |b| { + b.iter(|| bench_sort(&arr_a, &arr_b, None)) + }); + // with limit { - let arr_a = create_array(2u64.pow(12) as usize, false); - let arr_b = create_array(2u64.pow(12) as usize, false); + let arr_a = create_f32_array(2u64.pow(12) as usize, false); + let arr_b = create_f32_array(2u64.pow(12) as usize, false); c.bench_function("sort 2^12 limit 10", |b| { b.iter(|| bench_sort(&arr_a, &arr_b, Some(10))) }); - let arr_a = create_array(2u64.pow(12) as usize, false); - let arr_b = create_array(2u64.pow(12) as usize, false); + let arr_a = create_f32_array(2u64.pow(12) as usize, false); + let arr_b = create_f32_array(2u64.pow(12) as usize, false); c.bench_function("sort 2^12 limit 100", |b| { b.iter(|| bench_sort(&arr_a, &arr_b, Some(100))) }); - let arr_a = create_array(2u64.pow(12) as usize, false); - let arr_b = create_array(2u64.pow(12) as usize, false); + let arr_a = create_f32_array(2u64.pow(12) as usize, false); + let arr_b = create_f32_array(2u64.pow(12) as usize, false); c.bench_function("sort 2^12 limit 1000", |b| { b.iter(|| bench_sort(&arr_a, &arr_b, Some(1000))) }); - let arr_a = create_array(2u64.pow(12) as usize, false); - let arr_b = create_array(2u64.pow(12) as usize, false); + let arr_a = create_f32_array(2u64.pow(12) as usize, false); + let arr_b = create_f32_array(2u64.pow(12) as usize, false); c.bench_function("sort 2^12 limit 2^12", |b| { b.iter(|| bench_sort(&arr_a, &arr_b, Some(2u64.pow(12) as usize))) }); - let arr_a = create_array(2u64.pow(12) as usize, true); - let arr_b = create_array(2u64.pow(12) as usize, true); + let arr_a = create_f32_array(2u64.pow(12) as usize, true); + let arr_b = create_f32_array(2u64.pow(12) as usize, true); c.bench_function("sort nulls 2^12 limit 10", |b| { b.iter(|| bench_sort(&arr_a, &arr_b, Some(10)))