You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by mn...@apache.org on 2025/07/17 10:06:44 UTC

(datafusion) branch main updated: Benchmark for char expression (#16743)

This is an automated email from the ASF dual-hosted git repository.

mneumann pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 44e63e0f70 Benchmark for char expression (#16743)
44e63e0f70 is described below

commit 44e63e0f70d667ba0f4750b70b71170dc3120670
Author: Ajeeta Asthana <aj...@gmail.com>
AuthorDate: Thu Jul 17 06:06:40 2025 -0400

    Benchmark for char expression (#16743)
    
    * add benchmark for char function
    
    * add license header
    
    * add benchmarking
    
    * update return type
    
    * chore: fix benchmark
    
    ---------
    
    Co-authored-by: Yuri Astrakhan <Yu...@gmail.com>
---
 Cargo.lock                       |  2 ++
 datafusion/spark/Cargo.toml      |  8 +++++
 datafusion/spark/benches/char.rs | 74 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)

diff --git a/Cargo.lock b/Cargo.lock
index 0083f4ffbc..15997ef3d8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2607,6 +2607,7 @@ name = "datafusion-spark"
 version = "48.0.0"
 dependencies = [
  "arrow",
+ "criterion",
  "datafusion-catalog",
  "datafusion-common",
  "datafusion-execution",
@@ -2614,6 +2615,7 @@ dependencies = [
  "datafusion-functions",
  "datafusion-macros",
  "log",
+ "rand 0.9.1",
 ]
 
 [[package]]
diff --git a/datafusion/spark/Cargo.toml b/datafusion/spark/Cargo.toml
index 2c46cac6b7..9243103fff 100644
--- a/datafusion/spark/Cargo.toml
+++ b/datafusion/spark/Cargo.toml
@@ -44,3 +44,11 @@ datafusion-expr = { workspace = true }
 datafusion-functions = { workspace = true, features = ["crypto_expressions"] }
 datafusion-macros = { workspace = true }
 log = { workspace = true }
+
+[dev-dependencies]
+criterion = { workspace = true }
+rand = { workspace = true }
+
+[[bench]]
+harness = false
+name = "char"
diff --git a/datafusion/spark/benches/char.rs b/datafusion/spark/benches/char.rs
new file mode 100644
index 0000000000..b7819b5dd6
--- /dev/null
+++ b/datafusion/spark/benches/char.rs
@@ -0,0 +1,74 @@
+// 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.
+
+extern crate criterion;
+
+use arrow::datatypes::{DataType, Field};
+use arrow::{array::PrimitiveArray, datatypes::Int64Type};
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use datafusion_expr::{ColumnarValue, ScalarFunctionArgs};
+use datafusion_spark::function::string::char;
+use rand::rngs::StdRng;
+use rand::{Rng, SeedableRng};
+use std::sync::Arc;
+
+/// Returns fixed seedable RNG
+pub fn seedable_rng() -> StdRng {
+    StdRng::seed_from_u64(42)
+}
+
+fn criterion_benchmark(c: &mut Criterion) {
+    let cot_fn = char();
+    let size = 1024;
+    let input: PrimitiveArray<Int64Type> = {
+        let null_density = 0.2;
+        let mut rng = StdRng::seed_from_u64(42);
+        (0..size)
+            .map(|_| {
+                if rng.random::<f32>() < null_density {
+                    None
+                } else {
+                    Some(rng.random_range::<i64, _>(1i64..10_000))
+                }
+            })
+            .collect()
+    };
+    let input = Arc::new(input);
+    let args = vec![ColumnarValue::Array(input)];
+    let arg_fields = args
+        .iter()
+        .enumerate()
+        .map(|(idx, arg)| Field::new(format!("arg_{idx}"), arg.data_type(), true).into())
+        .collect::<Vec<_>>();
+
+    c.bench_function("char", |b| {
+        b.iter(|| {
+            black_box(
+                cot_fn
+                    .invoke_with_args(ScalarFunctionArgs {
+                        args: args.clone(),
+                        arg_fields: arg_fields.clone(),
+                        number_rows: size,
+                        return_field: Arc::new(Field::new("f", DataType::Utf8, true)),
+                    })
+                    .unwrap(),
+            )
+        })
+    });
+}
+criterion_group!(benches, criterion_benchmark);
+criterion_main!(benches);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org