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