Skip to content

Commit 4ac1b17

Browse files
committed
Add benchmark for casting to RunEndEncoded (REE)
1 parent e9a7fe5 commit 4ac1b17

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

arrow-cast/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ harness = false
7474
[[bench]]
7575
name = "parse_decimal"
7676
harness = false
77+
78+
[[bench]]
79+
name = "cast_ree"
80+
harness = false

arrow-cast/benches/cast_ree.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use arrow_array::*;
19+
use arrow_cast::cast;
20+
use arrow_schema::{DataType, Field};
21+
use criterion::*;
22+
use std::sync::Arc;
23+
24+
fn criterion_benchmark(c: &mut Criterion) {
25+
c.bench_function("string single run, 1_000_000 elements", |b| {
26+
let source_array = StringArray::from(vec!["a"; 1_000_000]);
27+
let array_ref = Arc::new(source_array) as ArrayRef;
28+
let target_type = DataType::RunEndEncoded(
29+
Arc::new(Field::new("run_ends", DataType::Int32, false)),
30+
Arc::new(Field::new("values", DataType::Utf8, true)),
31+
);
32+
b.iter(|| cast(&array_ref, &target_type).unwrap());
33+
});
34+
35+
c.bench_function("int32 many runs of 10, 1_000_000 elements", |b| {
36+
let source_array: Int32Array = (0..1_000_000).map(|i| i / 10).collect();
37+
let array_ref = Arc::new(source_array) as ArrayRef;
38+
let target_type = DataType::RunEndEncoded(
39+
Arc::new(Field::new("run_ends", DataType::Int32, false)),
40+
Arc::new(Field::new("values", DataType::Int32, true)),
41+
);
42+
b.iter(|| cast(&array_ref, &target_type).unwrap());
43+
});
44+
45+
c.bench_function("int32 many runs of 1000, 1_000_000 elements", |b| {
46+
let source_array: Int32Array = (0..1_000_000).map(|i| i / 1000).collect();
47+
let array_ref = Arc::new(source_array) as ArrayRef;
48+
let target_type = DataType::RunEndEncoded(
49+
Arc::new(Field::new("run_ends", DataType::Int32, false)),
50+
Arc::new(Field::new("values", DataType::Int32, true)),
51+
);
52+
b.iter(|| cast(&array_ref, &target_type).unwrap());
53+
});
54+
55+
c.bench_function("int32 no runs, 1_000_000 elements", |b| {
56+
let source_array: Int32Array = (0..1_000_000).collect();
57+
let array_ref = Arc::new(source_array) as ArrayRef;
58+
let target_type = DataType::RunEndEncoded(
59+
Arc::new(Field::new("run_ends", DataType::Int32, false)),
60+
Arc::new(Field::new("values", DataType::Int32, true)),
61+
);
62+
b.iter(|| cast(&array_ref, &target_type).unwrap());
63+
});
64+
}
65+
66+
criterion_group!(benches, criterion_benchmark);
67+
criterion_main!(benches);

0 commit comments

Comments
 (0)