Skip to content
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
8 changes: 8 additions & 0 deletions native/spark-expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,18 @@ harness = false
name = "abs"
harness = false

[[bench]]
name = "modulo"
harness = false

[[bench]]
name = "levenshtein"
harness = false

[[bench]]
name = "negative"
harness = false

[[bench]]
name = "split"
harness = false
Expand Down
51 changes: 51 additions & 0 deletions native/spark-expr/benches/modulo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use datafusion::physical_plan::ColumnarValue;
use datafusion_comet_spark_expr::spark_modulo;
use std::hint::black_box;
use std::sync::Arc;

#[path = "common/mod.rs"]
mod common;
use common::{i64_array, NULL_RATIOS, ROW_COUNTS};

fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("spark_modulo");
for rows in ROW_COUNTS {
// Divisor fully populated and non-zero so the benchmark measures the modulo, not the
// divide-by-zero null path.
let divisor = i64_array(rows, 0.0, |i| (i as i64 % 7) + 1);
for (null_ratio, tag) in NULL_RATIOS {
let dividend = i64_array(rows, null_ratio, |i| i as i64 % 1000);
let args = vec![
ColumnarValue::Array(dividend),
ColumnarValue::Array(Arc::clone(&divisor)),
];
group.bench_with_input(
BenchmarkId::from_parameter(format!("{rows}/{tag}")),
&args,
|b, args| b.iter(|| black_box(spark_modulo(black_box(args), false).unwrap())),
);
}
}
group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
53 changes: 53 additions & 0 deletions native/spark-expr/benches/negative.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use arrow::array::RecordBatch;
use arrow::datatypes::{DataType, Field, Schema};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use datafusion::physical_expr::expressions::Column;
use datafusion_comet_spark_expr::create_negate_expr;
use std::hint::black_box;
use std::sync::Arc;

#[path = "common/mod.rs"]
mod common;
use common::{i64_array, NULL_RATIOS, ROW_COUNTS};

fn criterion_benchmark(c: &mut Criterion) {
let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int64, true)]));
let expr = create_negate_expr(Arc::new(Column::new("a", 0)), false).unwrap();

let mut group = c.benchmark_group("negative");
for rows in ROW_COUNTS {
for (null_ratio, tag) in NULL_RATIOS {
let batch = RecordBatch::try_new(
Arc::clone(&schema),
vec![i64_array(rows, null_ratio, |i| i as i64 % 1000)],
)
.unwrap();
group.bench_with_input(
BenchmarkId::from_parameter(format!("{rows}/{tag}")),
&batch,
|b, batch| b.iter(|| black_box(expr.evaluate(black_box(batch)).unwrap())),
);
}
}
group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
6 changes: 3 additions & 3 deletions native/spark-expr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ pub use json_funcs::{FromJson, ToJson};
pub use math_funcs::{
abs, checked_add, checked_div, checked_mul, checked_sub, create_modulo_expr,
create_negate_expr, spark_ceil, spark_decimal_div, spark_decimal_integral_div, spark_floor,
spark_log, spark_make_decimal, spark_pow, spark_round, spark_unhex, spark_unscaled_value,
CheckOverflow, DecimalRescaleCheckOverflow, NegativeExpr, NormalizeNaNAndZero,
WideDecimalBinaryExpr, WideDecimalOp,
spark_log, spark_make_decimal, spark_modulo, spark_pow, spark_round, spark_unhex,
spark_unscaled_value, CheckOverflow, DecimalRescaleCheckOverflow, NegativeExpr,
NormalizeNaNAndZero, WideDecimalBinaryExpr, WideDecimalOp,
};
pub use query_context::{create_query_context_map, QueryContext, QueryContextMap};
pub use string_funcs::*;
Expand Down
2 changes: 1 addition & 1 deletion native/spark-expr/src/math_funcs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub use div::spark_decimal_integral_div;
pub use floor::spark_floor;
pub use internal::*;
pub use log::spark_log;
pub use modulo_expr::create_modulo_expr;
pub use modulo_expr::{create_modulo_expr, spark_modulo};
pub use negative::{create_negate_expr, NegativeExpr};
pub use pow::spark_pow;
pub use round::spark_round;
Expand Down
Loading