Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Improved benches.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Nov 26, 2021
1 parent e8279a4 commit 0f35ebe
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 172 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ full = [
"regex",
"compute",
# parses timezones used in timestamp conversions
"chrono-tz"
"chrono-tz",
]
io_csv = ["io_csv_read", "io_csv_write"]
io_csv_async = ["io_csv_read_async"]
Expand Down
6 changes: 3 additions & 3 deletions benches/aggregate.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::array::*;
use arrow2::compute::aggregate::*;
use arrow2::util::bench_util::*;
use arrow2::{compute::aggregate::*, datatypes::DataType};

fn bench_sum(arr_a: &PrimitiveArray<f32>) {
sum(criterion::black_box(arr_a)).unwrap();
Expand All @@ -15,7 +15,7 @@ fn bench_min(arr_a: &PrimitiveArray<f32>) {
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::<f32>(size, DataType::Float32, 0.0);
let arr_a = create_primitive_array::<f32>(size, 0.0);

c.bench_function(&format!("sum 2^{} f32", log2_size), |b| {
b.iter(|| bench_sum(&arr_a))
Expand All @@ -24,7 +24,7 @@ fn add_benchmark(c: &mut Criterion) {
b.iter(|| bench_min(&arr_a))
});

let arr_a = create_primitive_array::<f32>(size, DataType::Float32, 0.1);
let arr_a = create_primitive_array::<f32>(size, 0.1);

c.bench_function(&format!("sum null 2^{} f32", log2_size), |b| {
b.iter(|| bench_sum(&arr_a))
Expand Down
11 changes: 4 additions & 7 deletions benches/arithmetic_kernels.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#[macro_use]
extern crate criterion;
use criterion::Criterion;
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::array::*;
use arrow2::util::bench_util::*;
use arrow2::{
compute::arithmetics::basic::add, compute::arithmetics::basic::div_scalar, datatypes::DataType,
types::NativeType,
compute::arithmetics::basic::add, compute::arithmetics::basic::div_scalar, types::NativeType,
};
use num_traits::NumCast;
use std::ops::{Add, Div};
Expand All @@ -28,8 +25,8 @@ where
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::<u64>(size, DataType::UInt64, 0.0, 43);
let arr_b = create_primitive_array_with_seed::<u64>(size, DataType::UInt64, 0.0, 42);
let arr_a = create_primitive_array_with_seed::<u64>(size, 0.0, 43);
let arr_b = create_primitive_array_with_seed::<u64>(size, 0.0, 42);

c.bench_function(&format!("divide_scalar 2^{}", log2_size), |b| {
// 4 is a very fast optimizable divisor
Expand Down
6 changes: 1 addition & 5 deletions benches/bitmap.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
extern crate arrow2;

use std::iter::FromIterator;

use arrow2::bitmap::*;

use criterion::{criterion_group, criterion_main, Criterion};

//
use arrow2::bitmap::*;

fn add_benchmark(c: &mut Criterion) {
(10..=20).step_by(2).for_each(|log2_size| {
Expand Down
4 changes: 2 additions & 2 deletions benches/bitmap_ops.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use arrow2::bitmap::Bitmap;

use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::bitmap::Bitmap;

fn bench_arrow2(lhs: &Bitmap, rhs: &Bitmap) {
let r = lhs | rhs;
assert!(r.null_count() > 0);
Expand Down
19 changes: 7 additions & 12 deletions benches/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,29 @@ use criterion::{criterion_group, criterion_main, Criterion};
use num_traits::NumCast;

use arrow2::{
array::PrimitiveArray,
compute::bitwise::*,
datatypes::DataType,
types::NativeType,
util::bench_util::{
create_boolean_array, create_primitive_array, create_primitive_array_with_seed,
},
array::PrimitiveArray, compute::bitwise::*, types::NativeType,
util::bench_util::create_primitive_array_with_seed,
};

fn bench_or<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>)
where
T: NativeType + BitOr<Output = T> + NumCast,
{
criterion::black_box(or(lhs, rhs)).unwrap();
criterion::black_box(or(lhs, rhs));
}

fn bench_xor<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>)
where
T: NativeType + BitXor<Output = T> + NumCast,
{
criterion::black_box(xor(lhs, rhs)).unwrap();
criterion::black_box(xor(lhs, rhs));
}

fn bench_and<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>)
where
T: NativeType + BitAnd<Output = T> + NumCast,
{
criterion::black_box(and(lhs, rhs)).unwrap();
criterion::black_box(and(lhs, rhs));
}

fn bench_not<T>(arr: &PrimitiveArray<T>)
Expand All @@ -44,8 +39,8 @@ where
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::<u64>(size, DataType::UInt64, 0.0, 43);
let arr_b = create_primitive_array_with_seed::<u64>(size, DataType::UInt64, 0.0, 42);
let arr_a = create_primitive_array_with_seed::<u64>(size, 0.0, 43);
let arr_b = create_primitive_array_with_seed::<u64>(size, 0.0, 42);

c.bench_function(&format!("or 2^{}", log2_size), |b| {
b.iter(|| bench_or(&arr_a, &arr_b))
Expand Down
32 changes: 15 additions & 17 deletions benches/cast_kernels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
// specific language governing permissions and limitations
// under the License.

#[macro_use]
extern crate criterion;
use criterion::Criterion;
use criterion::{criterion_group, criterion_main, Criterion};
use rand::distributions::Uniform;
use rand::Rng;

Expand Down Expand Up @@ -72,27 +70,27 @@ fn build_utf8_date_time_array(size: usize, with_nulls: bool) -> Utf8Array<i32> {

// cast array from specified primitive array type to desired data type
fn cast_array(array: &dyn Array, to_type: DataType) {
criterion::black_box(cast::cast(array, &to_type).unwrap());
criterion::black_box(cast::cast(array, &to_type, Default::default()).unwrap());
}

fn add_benchmark(c: &mut Criterion) {
let size = 512;
let i32_array = create_primitive_array::<i32>(size, DataType::Int32, 0.1);
let i64_array = create_primitive_array::<i64>(size, DataType::Int64, 0.1);
let f32_array = create_primitive_array::<f32>(size, DataType::Float32, 0.1);
let f32_utf8_array = cast::cast(&f32_array, &DataType::Utf8).unwrap();
let i32_array = create_primitive_array::<i32>(size, 0.1);
let i64_array = create_primitive_array::<i64>(size, 0.1);
let f32_array = create_primitive_array::<f32>(size, 0.1);
let f32_utf8_array = cast::cast(&f32_array, &DataType::Utf8, Default::default()).unwrap();

let f64_array = create_primitive_array::<f64>(size, DataType::Float64, 0.1);
let date64_array = create_primitive_array::<i64>(size, DataType::Date64, 0.1);
let date32_array = create_primitive_array::<i32>(size, DataType::Date32, 0.1);
let f64_array = create_primitive_array::<f64>(size, 0.1);
let date64_array = create_primitive_array::<i64>(size, 0.1).to(DataType::Date64);
let date32_array = create_primitive_array::<i32>(size, 0.1).to(DataType::Date32);
let time32s_array =
create_primitive_array::<i32>(size, DataType::Time32(TimeUnit::Second), 0.1);
create_primitive_array::<i32>(size, 0.1).to(DataType::Time32(TimeUnit::Second));
let time64ns_array =
create_primitive_array::<i64>(size, DataType::Time64(TimeUnit::Nanosecond), 0.1);
let time_ns_array =
create_primitive_array::<i64>(size, DataType::Timestamp(TimeUnit::Nanosecond, None), 0.1);
let time_ms_array =
create_primitive_array::<i64>(size, DataType::Timestamp(TimeUnit::Millisecond, None), 0.1);
create_primitive_array::<i64>(size, 0.1).to(DataType::Time64(TimeUnit::Nanosecond));
let time_ns_array = create_primitive_array::<i64>(size, 0.1)
.to(DataType::Timestamp(TimeUnit::Nanosecond, None));
let time_ms_array = create_primitive_array::<i64>(size, 0.1)
.to(DataType::Timestamp(TimeUnit::Millisecond, None));
let utf8_date_array = build_utf8_date_array(512, true);
let utf8_date_time_array = build_utf8_date_time_array(512, true);

Expand Down
6 changes: 3 additions & 3 deletions benches/comparison_kernels.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::compute::comparison::{eq, eq_scalar};
use arrow2::scalar::*;
use arrow2::util::bench_util::*;
use arrow2::{compute::comparison::eq, datatypes::DataType};

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::<f32>(size, DataType::Float32, 0.0, 42);
let arr_b = create_primitive_array_with_seed::<f32>(size, DataType::Float32, 0.0, 43);
let arr_a = create_primitive_array_with_seed::<f32>(size, 0.0, 42);
let arr_b = create_primitive_array_with_seed::<f32>(size, 0.0, 43);

c.bench_function(&format!("f32 2^{}", log2_size), |b| {
b.iter(|| eq(&arr_a, &arr_b))
Expand Down
11 changes: 4 additions & 7 deletions benches/concatenate.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
extern crate arrow2;
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::{
compute::concatenate::concatenate,
datatypes::DataType,
util::bench_util::{create_boolean_array, create_primitive_array},
};

use criterion::{criterion_group, criterion_main, Criterion};

fn add_benchmark(c: &mut Criterion) {
(20..=20).step_by(2).for_each(|log2_size| {
let size = 2usize.pow(log2_size);

let array1 = create_primitive_array::<i32>(8, DataType::Int32, 0.5);
let array2 = create_primitive_array::<i32>(size + 1, DataType::Int32, 0.5);
let array1 = create_primitive_array::<i32>(8, 0.5);
let array2 = create_primitive_array::<i32>(size + 1, 0.5);

c.bench_function(&format!("int32 concat aligned 2^{}", log2_size), |b| {
b.iter(|| {
let _ = concatenate(&[&array1, &array2]);
})
});

let array1 = create_primitive_array::<i32>(9, DataType::Int32, 0.5);
let array1 = create_primitive_array::<i32>(9, 0.5);

c.bench_function(&format!("int32 concat unaligned 2^{}", log2_size), |b| {
b.iter(|| {
Expand Down
4 changes: 2 additions & 2 deletions benches/count_zeros.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use arrow2::bitmap::utils::count_zeros;

use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::bitmap::utils::count_zeros;

fn add_benchmark(c: &mut Criterion) {
(10..=20).step_by(2).for_each(|log2_size| {
let size = 2usize.pow(log2_size);
Expand Down
18 changes: 8 additions & 10 deletions benches/filter_kernels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
extern crate arrow2;

use std::sync::Arc;

use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::array::*;
use arrow2::compute::filter::{build_filter, filter, filter_record_batch, Filter};
use arrow2::datatypes::{DataType, Field, Schema};
use arrow2::record_batch::RecordBatch;

use arrow2::util::bench_util::{create_boolean_array, create_primitive_array, create_string_array};
use criterion::{criterion_group, criterion_main, Criterion};

fn bench_filter(data_array: &dyn Array, filter_array: &BooleanArray) {
criterion::black_box(filter(data_array, filter_array).unwrap());
Expand All @@ -43,12 +41,12 @@ fn add_benchmark(c: &mut Criterion) {
let filter_array =
BooleanArray::from_data(DataType::Boolean, filter_array.values().clone(), None);

let arr_a = create_primitive_array::<f32>(size, DataType::Float32, 0.0);
let arr_a = create_primitive_array::<f32>(size, 0.0);
c.bench_function(&format!("filter 2^{} f32", log2_size), |b| {
b.iter(|| bench_filter(&arr_a, &filter_array))
});

let arr_a = create_primitive_array::<f32>(size, DataType::Float32, 0.1);
let arr_a = create_primitive_array::<f32>(size, 0.1);

c.bench_function(&format!("filter null 2^{} f32", log2_size), |b| {
b.iter(|| bench_filter(&arr_a, &filter_array))
Expand All @@ -64,7 +62,7 @@ fn add_benchmark(c: &mut Criterion) {
let dense_filter = build_filter(&dense_filter_array).unwrap();
let sparse_filter = build_filter(&sparse_filter_array).unwrap();

let data_array = create_primitive_array::<u8>(size, DataType::UInt8, 0.0);
let data_array = create_primitive_array::<u8>(size, 0.0);

c.bench_function("filter u8", |b| {
b.iter(|| bench_filter(&data_array, &filter_array))
Expand All @@ -86,7 +84,7 @@ fn add_benchmark(c: &mut Criterion) {
b.iter(|| bench_built_filter(&sparse_filter, &data_array))
});

let data_array = create_primitive_array::<u8>(size, DataType::UInt8, 0.5);
let data_array = create_primitive_array::<u8>(size, 0.5);
c.bench_function("filter context u8 w NULLs", |b| {
b.iter(|| bench_built_filter(&filter, &data_array))
});
Expand All @@ -97,7 +95,7 @@ fn add_benchmark(c: &mut Criterion) {
b.iter(|| bench_built_filter(&sparse_filter, &data_array))
});

let data_array = create_primitive_array::<f32>(size, DataType::Float32, 0.5);
let data_array = create_primitive_array::<f32>(size, 0.5);
c.bench_function("filter f32", |b| {
b.iter(|| bench_filter(&data_array, &filter_array))
});
Expand Down Expand Up @@ -125,7 +123,7 @@ fn add_benchmark(c: &mut Criterion) {
b.iter(|| bench_built_filter(&sparse_filter, &data_array))
});

let data_array = create_primitive_array::<f32>(size, DataType::Float32, 0.0);
let data_array = create_primitive_array::<f32>(size, 0.0);

let field = Field::new("c1", data_array.data_type().clone(), true);
let schema = Schema::new(vec![field]);
Expand Down
4 changes: 1 addition & 3 deletions benches/from_trusted_len_iter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
extern crate arrow2;
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::{array::PrimitiveArray, bitmap::*, buffer::*};

use criterion::{criterion_group, criterion_main, Criterion};

fn add_benchmark(c: &mut Criterion) {
let values = 0..1026;

Expand Down
11 changes: 4 additions & 7 deletions benches/growable.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
extern crate arrow2;
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::{
array::growable::{Growable, GrowablePrimitive},
datatypes::DataType,
util::bench_util::create_primitive_array,
};

use criterion::{criterion_group, criterion_main, Criterion};

fn add_benchmark(c: &mut Criterion) {
let values = (0..1026).rev();

let i32_array = create_primitive_array::<i32>(1026 * 10, DataType::Int32, 0.0);
let i32_array = create_primitive_array::<i32>(1026 * 10, 0.0);
c.bench_function("growable::primitive::non_null::non_null", |b| {
b.iter(|| {
let mut a = GrowablePrimitive::new(vec![&i32_array], false, 1026 * 10);
Expand All @@ -22,7 +19,7 @@ fn add_benchmark(c: &mut Criterion) {
})
});

let i32_array = create_primitive_array::<i32>(1026 * 10, DataType::Int32, 0.0);
let i32_array = create_primitive_array::<i32>(1026 * 10, 0.0);
c.bench_function("growable::primitive::non_null::null", |b| {
b.iter(|| {
let mut a = GrowablePrimitive::new(vec![&i32_array], true, 1026 * 10);
Expand All @@ -36,7 +33,7 @@ fn add_benchmark(c: &mut Criterion) {
})
});

let i32_array = create_primitive_array::<i32>(1026 * 10, DataType::Int32, 0.1);
let i32_array = create_primitive_array::<i32>(1026 * 10, 0.1);

let values = values.collect::<Vec<_>>();
c.bench_function("growable::primitive::null::non_null", |b| {
Expand Down
9 changes: 3 additions & 6 deletions benches/hash_kernel.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
extern crate arrow2;
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::compute::hash::hash;
use arrow2::datatypes::DataType;
use arrow2::util::bench_util::*;

use criterion::{criterion_group, criterion_main, Criterion};

fn add_benchmark(c: &mut Criterion) {
let log2_size = 10;
let size = 2usize.pow(log2_size);

let arr_a = create_primitive_array::<i32>(size, DataType::Int32, 0.0);
let arr_a = create_primitive_array::<i32>(size, 0.0);

c.bench_function(&format!("i32 2^{}", log2_size), |b| b.iter(|| hash(&arr_a)));

let arr_a = create_primitive_array::<i64>(size, DataType::Int64, 0.0);
let arr_a = create_primitive_array::<i64>(size, 0.0);

c.bench_function(&format!("i64 2^{}", log2_size), |b| b.iter(|| hash(&arr_a)));

Expand Down
Loading

0 comments on commit 0f35ebe

Please sign in to comment.