Skip to content

Commit 01fab95

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

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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("single run", |b| {
26+
let source_array = StringArray::from(vec!["a"; 1000000]);
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("many short runs", |b| {
36+
let source_array: Int32Array = (0..1000000).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("no runs", |b| {
46+
let source_array: Int32Array = (0..1000000).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+
56+
criterion_group!(benches, criterion_benchmark);
57+
criterion_main!(benches);

0 commit comments

Comments
 (0)