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

Added cargo check to benchmarks #730

Merged
merged 3 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ jobs:
- uses: Swatinem/rust-cache@v1
- name: Run
run: cargo check-all-features
- name: Bench Check
run: cargo bench --no-run --features full,benchmarks

cross:
name: cross
Expand Down
9 changes: 4 additions & 5 deletions benches/arithmetic_kernels.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use arrow2::compute::arithmetics::basic::NativeArithmetics;
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, types::NativeType,
};
use arrow2::{compute::arithmetics::basic::add, compute::arithmetics::basic::div_scalar};
use num_traits::NumCast;
use std::ops::{Add, Div};

fn bench_div_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T)
where
T: NativeType + Div<Output = T> + NumCast,
T: NativeArithmetics + Div<Output = T> + NumCast,
{
criterion::black_box(div_scalar(lhs, rhs));
}

fn bench_add<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>)
where
T: NativeType + Add<Output = T> + NumCast,
T: NativeArithmetics + Add<Output = T> + NumCast,
{
criterion::black_box(add(lhs, rhs));
}
Expand Down
5 changes: 2 additions & 3 deletions benches/avro_read.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io::Cursor;
use std::sync::Arc;

use avro_rs::types::Record;
use criterion::*;
Expand Down Expand Up @@ -52,13 +51,13 @@ fn read_batch(buffer: &[u8], size: usize) -> Result<()> {
codec,
),
avro_schema,
Arc::new(schema),
schema.fields().clone(),
);

let mut rows = 0;
for maybe_batch in reader {
let batch = maybe_batch?;
rows += batch.num_rows();
rows += batch.len();
}
assert_eq!(rows, size);
Ok(())
Expand Down
13 changes: 6 additions & 7 deletions benches/filter_kernels.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
Expand All @@ -14,21 +16,19 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use std::sync::Arc;

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

use arrow2::array::*;
use arrow2::chunk::Chunk;
use arrow2::compute::filter::{build_filter, filter, filter_chunk, Filter};
use arrow2::datatypes::{DataType, Field, Schema};
use arrow2::datatypes::DataType;
use arrow2::util::bench_util::{create_boolean_array, create_primitive_array, create_string_array};

fn bench_filter(data_array: &dyn Array, filter_array: &BooleanArray) {
criterion::black_box(filter(data_array, filter_array).unwrap());
}

fn bench_built_filter<'a>(filter: &Filter<'a>, array: &impl Array) {
fn bench_built_filter<'a>(filter: &Filter<'a>, array: &dyn Array) {
criterion::black_box(filter(array));
}

Expand Down Expand Up @@ -125,10 +125,9 @@ fn add_benchmark(c: &mut Criterion) {

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

let columns = Chunk::try_new(vec![Arc::new(data_array)]).unwrap();

let columns = Chunk::try_new(vec![Arc::new(data_array) as ArrayRef]).unwrap();
c.bench_function("filter single record batch", |b| {
b.iter(|| filter_record_batch(&columns, &filter_array))
b.iter(|| filter_chunk(&columns, &filter_array))
});
}

Expand Down
6 changes: 4 additions & 2 deletions benches/write_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ use arrow2::error::Result;
use arrow2::io::csv::write;
use arrow2::util::bench_util::*;

fn write_batch(columns: &Chunk) -> Result<()> {
type ChunkArc = Chunk<Arc<dyn Array>>;

fn write_batch(columns: &ChunkArc) -> Result<()> {
let writer = &mut write::WriterBuilder::new().from_writer(vec![]);

assert_eq!(columns.arrays().len(), 1);
write::write_header(writer, &["a"])?;

let options = write::SerializeOptions::default();
write::write_batch(writer, batch, &options)
write::write_chunk(writer, columns, &options)
}

fn make_chunk(array: impl Array + 'static) -> Chunk<Arc<dyn Array>> {
Expand Down
4 changes: 1 addition & 3 deletions benches/write_ipc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::io::Cursor;
use std::sync::Arc;

use criterion::{criterion_group, criterion_main, Criterion};
use std::io::Cursor;

use arrow2::array::*;
use arrow2::chunk::Chunk;
Expand Down
8 changes: 6 additions & 2 deletions benches/write_parquet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::io::Cursor;
use std::sync::Arc;

use arrow2::datatypes::{Field, Schema};
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::array::{clone, Array};
Expand All @@ -8,9 +10,11 @@ use arrow2::error::Result;
use arrow2::io::parquet::write::*;
use arrow2::util::bench_util::{create_boolean_array, create_primitive_array, create_string_array};

type ChunkArc = Chunk<Arc<dyn Array>>;

fn write(array: &dyn Array, encoding: Encoding) -> Result<()> {
let columns = Chunk::new(vec![clone(array).into()]);
let schema = batch.schema().clone();
let schema = Schema::new(vec![Field::new("c1", array.data_type().clone(), true)]);
let columns: ChunkArc = Chunk::new(vec![clone(array).into()]);

let options = WriteOptions {
write_statistics: false,
Expand Down