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

sdf-jkl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 01bb6a0a98 add cast benchmark for temporary types to string (#11058)
01bb6a0a98 is described below

commit 01bb6a0a98ff53ef5ad2d62889056a6e6f88b189
Author: Congxian Qiu <[email protected]>
AuthorDate: Sat Sep 12 02:53:14 2026 +0800

    add cast benchmark for temporary types to string (#11058)
    
    # Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax.
    -->
    
    - Closes #10987.
    
    
    # Are these changes tested?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they covered by existing tests)?
    
    If this PR claims a performance improvement, please include evidence
    such as benchmark results.
    -->
    
    This pr adds benchmarks, no tests needed
    
    # Are there any user-facing changes?
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    
    If there are any breaking changes to public APIs, please call them out.
    -->
    No
---
 arrow/benches/cast_kernels.rs | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/arrow/benches/cast_kernels.rs b/arrow/benches/cast_kernels.rs
index 2a6336b338..a5f79010af 100644
--- a/arrow/benches/cast_kernels.rs
+++ b/arrow/benches/cast_kernels.rs
@@ -22,7 +22,7 @@ use rand::RngExt;
 use rand::distr::{Distribution, StandardUniform, Uniform};
 use std::hint;
 
-use chrono::DateTime;
+use chrono::{DateTime, NaiveDate, NaiveDateTime};
 use std::sync::Arc;
 
 use arrow::array::*;
@@ -616,6 +616,38 @@ fn add_benchmark(c: &mut Criterion) {
         );
         b.iter(|| cast(&array_ref, &target_type).unwrap());
     });
+
+    c.bench_function("cast date to string", |b| {
+        // the min and max of the date32 type
+        let range = 
NaiveDate::MIN.to_epoch_days()..NaiveDate::MAX.to_epoch_days();
+        let date32_array: PrimitiveArray<Date32Type> =
+            create_primitive_array_range::<Date32Type>(8192, 0.1, range);
+        let target_type = DataType::Utf8;
+        b.iter(|| cast(&date32_array, &target_type).unwrap());
+    });
+    c.bench_function("cast time64 to string", |b| {
+        let time64_array: PrimitiveArray<Time64MicrosecondType> =
+            create_primitive_array_range::<Time64MicrosecondType>(8192, 0.1, 
0..86400000000);
+        let target_type = DataType::Utf8;
+        b.iter(|| cast(&time64_array, &target_type).unwrap());
+    });
+    c.bench_function("cast micro timestamp to string", |b| {
+        let range = NaiveDateTime::MIN.and_utc().timestamp_micros()
+            ..NaiveDateTime::MAX.and_utc().timestamp_micros();
+        let timestamp_micro_array: PrimitiveArray<TimestampMicrosecondType> =
+            create_primitive_array_range::<TimestampMicrosecondType>(8192, 
0.1, range);
+        let target_type = DataType::Utf8;
+        b.iter(|| cast(&timestamp_micro_array, &target_type).unwrap());
+    });
+    c.bench_function("cast micro timestamp with timezone to string", |b| {
+        let range = NaiveDateTime::MIN.and_utc().timestamp_micros()
+            ..NaiveDateTime::MAX.and_utc().timestamp_micros();
+        let timestamp_micro_utc_array =
+            create_primitive_array_range::<TimestampMicrosecondType>(8192, 
0.1, range)
+                .with_timezone("+08:00");
+        let target_type = DataType::Utf8;
+        b.iter(|| cast(&timestamp_micro_utc_array, &target_type).unwrap());
+    });
 }
 
 criterion_group!(benches, add_benchmark);

Reply via email to