Skip to content

Commit bcd62b4

Browse files
committed
add microbenchmark
Signed-off-by: Andrew Duffy <andrew@a10y.dev>
1 parent 6690fc0 commit bcd62b4

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

vortex-array/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,7 @@ harness = false
201201
[[bench]]
202202
name = "slice_dict_primitive"
203203
harness = false
204+
205+
[[bench]]
206+
name = "to_arrow"
207+
harness = false

vortex-array/benches/to_arrow.rs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use std::sync::Arc;
5+
6+
use divan::Bencher;
7+
use vortex_array::ArrayRef;
8+
use vortex_array::IntoArray;
9+
use vortex_array::LEGACY_SESSION;
10+
use vortex_array::VortexSessionExecute;
11+
use vortex_array::arrays::DecimalArray;
12+
use vortex_array::arrays::ListArray;
13+
use vortex_array::arrays::PrimitiveArray;
14+
use vortex_array::arrays::StructArray;
15+
#[expect(
16+
deprecated,
17+
reason = "benchmark comparing deprecated method with new one"
18+
)]
19+
use vortex_array::arrow::ArrowArrayExecutor;
20+
use vortex_array::arrow::ArrowSessionExt;
21+
use vortex_array::dtype::DType;
22+
use vortex_array::dtype::DecimalDType;
23+
use vortex_array::dtype::Nullability;
24+
use vortex_array::dtype::PType;
25+
use vortex_array::dtype::StructFields;
26+
27+
fn main() {
28+
divan::main();
29+
}
30+
31+
fn schema() -> DType {
32+
let fields = StructFields::from_iter([
33+
(
34+
"primitive",
35+
DType::Primitive(PType::F32, Nullability::Nullable),
36+
),
37+
(
38+
"list",
39+
DType::List(
40+
Arc::new(DType::Binary(Nullability::NonNullable)),
41+
Nullability::Nullable,
42+
),
43+
),
44+
(
45+
"decimal",
46+
DType::Decimal(DecimalDType::new(19, 10), Nullability::Nullable),
47+
),
48+
]);
49+
DType::Struct(fields, Nullability::NonNullable)
50+
}
51+
52+
fn array() -> ArrayRef {
53+
StructArray::from_fields(&[
54+
(
55+
"primitive",
56+
PrimitiveArray::from_iter(0i16..1024).into_array(),
57+
),
58+
(
59+
"list",
60+
ListArray::from_iter_slow::<u32, _>(
61+
(0..1024).map(|_| vec!["a", "b", "c"]).collect::<Vec<_>>(),
62+
Arc::new(DType::Utf8(Nullability::NonNullable)),
63+
)
64+
.unwrap()
65+
.into_array(),
66+
),
67+
(
68+
"decimal",
69+
DecimalArray::from_iter(0i64..1024, DecimalDType::new(19, 2)).into_array(),
70+
),
71+
])
72+
.unwrap()
73+
.into_array()
74+
}
75+
76+
#[divan::bench]
77+
fn to_arrow_dtype(bencher: Bencher) {
78+
bencher.with_inputs(|| schema()).bench_values(|dtype| {
79+
#[expect(deprecated, reason = "benchmarking deprecated code path")]
80+
dtype.to_arrow_dtype().unwrap()
81+
});
82+
}
83+
84+
#[allow(non_snake_case)]
85+
#[divan::bench]
86+
fn ArrowExportVTable_to_arrow_field(bencher: Bencher) {
87+
// Warm the ArrowSession
88+
drop(
89+
LEGACY_SESSION
90+
.arrow()
91+
.to_arrow_field("", &schema())
92+
.unwrap(),
93+
);
94+
95+
bencher
96+
.with_inputs(|| schema())
97+
.bench_values(|dtype| LEGACY_SESSION.arrow().to_arrow_field("", &dtype).unwrap())
98+
}
99+
100+
#[divan::bench]
101+
fn to_arrow_array(bencher: Bencher) {
102+
bencher
103+
.with_inputs(|| (array(), LEGACY_SESSION.create_execution_ctx()))
104+
.bench_values(|(array, mut ctx)| {
105+
#[expect(deprecated, reason = "benchmarking deprecated code path")]
106+
array.execute_arrow(None, &mut ctx).unwrap()
107+
});
108+
}
109+
110+
#[allow(non_snake_case)]
111+
#[divan::bench]
112+
fn ArrowExportVTable_execute_arrow(bencher: Bencher) {
113+
// Warm the ArrowSession
114+
drop(LEGACY_SESSION.arrow().execute_arrow(
115+
array(),
116+
None,
117+
&mut LEGACY_SESSION.create_execution_ctx(),
118+
));
119+
120+
bencher
121+
.with_inputs(|| (array(), LEGACY_SESSION.create_execution_ctx()))
122+
.bench_values(|(array, mut ctx)| {
123+
LEGACY_SESSION
124+
.arrow()
125+
.execute_arrow(array, None, &mut ctx)
126+
.unwrap()
127+
})
128+
}

0 commit comments

Comments
 (0)