Skip to content
Merged
Changes from all commits
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
37 changes: 21 additions & 16 deletions arrow/benches/boolean_kernels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,43 @@ fn bench_not(array: &BooleanArray) {
}

fn add_benchmark(c: &mut Criterion) {
// allocate arrays of 32K elements
let size = 2usize.pow(15);

// Note we allocate all arrays before the benchmark to ensure the allocation of the arrays
// is not affected by allocations that happen during the benchmarked operation.
let array1 = create_boolean_array(size, 0.0, 0.5);
let array2 = create_boolean_array(size, 0.0, 0.5);
c.bench_function("and", |b| b.iter(|| bench_and(&array1, &array2)));
c.bench_function("or", |b| b.iter(|| bench_or(&array1, &array2)));
c.bench_function("not", |b| b.iter(|| bench_not(&array1)));

// Slice by 1 (not aligned to byte (8 bit) or word (64 bit) boundaries)
let offset = 1;
let array1_slice = array1.slice(offset, size - offset);
let array2_slice = array2.slice(offset, size - offset);
let array1_sliced_1 = array1.slice(offset, size - offset);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main change is to allocate all the inputs arrays before running the benchmarks

I had to rename some of the variables anyways, so I took the opportunity to rename them to reflect the names used in the benchmark descriptions as well

let array2_sliced_1 = array2.slice(offset, size - offset);

// Slice by 24 (aligned on byte (8 bit) but not word (64 bit) boundaries)
let offset = 24;
let array1_sliced_24 = array1.slice(offset, size - offset);
let array2_sliced_24 = array2.slice(offset, size - offset);

c.bench_function("and", |b| b.iter(|| bench_and(&array1, &array2)));
c.bench_function("or", |b| b.iter(|| bench_or(&array1, &array2)));
c.bench_function("not", |b| b.iter(|| bench_not(&array1)));

c.bench_function("and_sliced_1", |b| {
b.iter(|| bench_and(&array1_slice, &array2_slice))
b.iter(|| bench_and(&array1_sliced_1, &array2_sliced_1))
});
c.bench_function("or_sliced_1", |b| {
b.iter(|| bench_or(&array1_slice, &array2_slice))
b.iter(|| bench_or(&array1_sliced_1, &array2_sliced_1))
});
c.bench_function("not_sliced_1", |b| b.iter(|| bench_not(&array1_slice)));

// Slice by 24 (aligned on byte (8 bit) but not word (64 bit) boundaries)
let offset = 24;
let array1_slice = array1.slice(offset, size - offset);
let array2_slice = array2.slice(offset, size - offset);
c.bench_function("not_sliced_1", |b| b.iter(|| bench_not(&array1_sliced_1)));

c.bench_function("and_sliced_24", |b| {
b.iter(|| bench_and(&array1_slice, &array2_slice))
b.iter(|| bench_and(&array1_sliced_24, &array2_sliced_24))
});
c.bench_function("or_sliced_24", |b| {
b.iter(|| bench_or(&array1_slice, &array2_slice))
b.iter(|| bench_or(&array1_sliced_24, &array2_sliced_24))
});
c.bench_function("not_slice_24", |b| b.iter(|| bench_not(&array1_slice)));
c.bench_function("not_slice_24", |b| b.iter(|| bench_not(&array1_sliced_24)));
}

criterion_group!(benches, add_benchmark);
Expand Down
Loading