Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sort boolean benchmark #457

Merged
merged 2 commits into from
Jun 19, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions arrow/benches/sort_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ 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::<Float32Type>(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<usize>) {
let columns = vec![
SortColumn {
Expand All @@ -49,58 +57,70 @@ fn bench_sort(array_a: &ArrayRef, array_b: &ArrayRef, limit: Option<usize>) {
}

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)))
Expand Down