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

github-bot 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 7b5685baa7 Add benchmark for array_reverse (#18425)
7b5685baa7 is described below

commit 7b5685baa7043f8a99ee6613050eeaaa575a50dc
Author: Vegard Stikbakke <[email protected]>
AuthorDate: Wed Nov 5 12:27:04 2025 +0100

    Add benchmark for array_reverse (#18425)
    
    There's no benchmarks for `array_reverse`. I used this while working on
    #18424 to confirm `take` was faster than MutableData for ListView. That
    might be the case for other List types as well, which are currently
    using `MutableData`.
    
    The benchmark can be run with `cargo bench --bench array_reverse`.
---
 datafusion/functions-nested/Cargo.toml             |  4 ++
 .../functions-nested/benches/array_reverse.rs      | 78 ++++++++++++++++++++++
 2 files changed, 82 insertions(+)

diff --git a/datafusion/functions-nested/Cargo.toml 
b/datafusion/functions-nested/Cargo.toml
index 9c0b7a16f9..6e0d1048f9 100644
--- a/datafusion/functions-nested/Cargo.toml
+++ b/datafusion/functions-nested/Cargo.toml
@@ -66,6 +66,10 @@ rand = { workspace = true }
 harness = false
 name = "array_expression"
 
+[[bench]]
+harness = false
+name = "array_reverse"
+
 [[bench]]
 harness = false
 name = "map"
diff --git a/datafusion/functions-nested/benches/array_reverse.rs 
b/datafusion/functions-nested/benches/array_reverse.rs
new file mode 100644
index 0000000000..d4a63e3640
--- /dev/null
+++ b/datafusion/functions-nested/benches/array_reverse.rs
@@ -0,0 +1,78 @@
+// 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.
+
+#[macro_use]
+extern crate criterion;
+extern crate arrow;
+
+use std::{hint::black_box, sync::Arc};
+
+use crate::criterion::Criterion;
+use arrow::{
+    array::{ArrayRef, FixedSizeListArray, Int32Array, ListArray, 
ListViewArray},
+    buffer::{OffsetBuffer, ScalarBuffer},
+    datatypes::{DataType, Field},
+};
+use datafusion_functions_nested::reverse::array_reverse_inner;
+
+fn array_reverse(array: &ArrayRef) -> ArrayRef {
+    black_box(array_reverse_inner(std::slice::from_ref(array)).unwrap())
+}
+
+fn criterion_benchmark(c: &mut Criterion) {
+    // Construct large arrays for benchmarking
+    let array_len = 100000;
+    let step_size: usize = 1000;
+    let offsets: Vec<i32> = (0..array_len as i32).step_by(step_size).collect();
+    let offsets = ScalarBuffer::from(offsets);
+    let sizes: Vec<i32> = vec![step_size as i32; array_len / step_size];
+    let values = (0..array_len as i32).collect::<Vec<i32>>();
+    let list_array: ArrayRef = Arc::new(ListArray::new(
+        Arc::new(Field::new("a", DataType::Int32, false)),
+        OffsetBuffer::new(offsets.clone()),
+        Arc::new(Int32Array::from(values.clone())),
+        None,
+    ));
+    let fixed_size_list_array: ArrayRef = Arc::new(FixedSizeListArray::new(
+        Arc::new(Field::new("a", DataType::Int32, false)),
+        step_size as i32,
+        Arc::new(Int32Array::from(values.clone())),
+        None,
+    ));
+    let list_view_array: ArrayRef = Arc::new(ListViewArray::new(
+        Arc::new(Field::new("a", DataType::Int32, false)),
+        offsets,
+        ScalarBuffer::from(sizes),
+        Arc::new(Int32Array::from(values)),
+        None,
+    ));
+
+    c.bench_function("array_reverse_list", |b| {
+        b.iter(|| array_reverse(&list_array))
+    });
+
+    c.bench_function("array_reverse_fixed_size_list", |b| {
+        b.iter(|| array_reverse(&fixed_size_list_array))
+    });
+
+    c.bench_function("array_reverse_list_view", |b| {
+        b.iter(|| array_reverse(&list_view_array))
+    });
+}
+
+criterion_group!(benches, criterion_benchmark);
+criterion_main!(benches);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to