Skip to content

Commit 4fc9ad1

Browse files
authored
Benchmark for casting view to dict arrays (and the reverse) (#5874)
* add benchmark * make clippy happy * move to arrow workspace
1 parent 0cc1416 commit 4fc9ad1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

arrow/benches/cast_kernels.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ fn build_decimal256_array(size: usize, precision: u8, scale: i8) -> ArrayRef {
114114
)
115115
}
116116

117+
fn build_dict_array(size: usize) -> ArrayRef {
118+
let values = StringArray::from_iter([
119+
Some("small"),
120+
Some("larger string more than 12 bytes"),
121+
None,
122+
]);
123+
let keys = UInt64Array::from_iter((0..size as u64).map(|v| v % 3));
124+
125+
Arc::new(DictionaryArray::new(keys, Arc::new(values)))
126+
}
127+
117128
// cast array from specified primitive array type to desired data type
118129
fn cast_array(array: &ArrayRef, to_type: DataType) {
119130
criterion::black_box(cast(array, &to_type).unwrap());
@@ -138,6 +149,9 @@ fn add_benchmark(c: &mut Criterion) {
138149
let decimal128_array = build_decimal128_array(512, 10, 3);
139150
let decimal256_array = build_decimal256_array(512, 50, 3);
140151

152+
let dict_array = build_dict_array(10_000);
153+
let string_view_array = cast(&dict_array, &DataType::Utf8View).unwrap();
154+
141155
c.bench_function("cast int32 to int32 512", |b| {
142156
b.iter(|| cast_array(&i32_array, DataType::Int32))
143157
});
@@ -237,6 +251,17 @@ fn add_benchmark(c: &mut Criterion) {
237251
c.bench_function("cast decimal256 to decimal256 512 with same scale", |b| {
238252
b.iter(|| cast_array(&decimal256_array, DataType::Decimal256(60, 3)))
239253
});
254+
c.bench_function("cast dict to string view", |b| {
255+
b.iter(|| cast_array(&dict_array, DataType::Utf8View))
256+
});
257+
c.bench_function("cast string view to dict", |b| {
258+
b.iter(|| {
259+
cast_array(
260+
&string_view_array,
261+
DataType::Dictionary(Box::new(DataType::UInt64), Box::new(DataType::Utf8)),
262+
)
263+
})
264+
});
240265
}
241266

242267
criterion_group!(benches, add_benchmark);

0 commit comments

Comments
 (0)