forked from jorgecarleitao/arrow2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiter_utf8.rs
34 lines (28 loc) · 970 Bytes
/
iter_utf8.rs
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
use criterion::{criterion_group, criterion_main, Criterion};
use arrow2::array::Utf8Array;
fn add_benchmark(c: &mut Criterion) {
(10..=20).step_by(2).for_each(|log2_size| {
let size = 2usize.pow(log2_size);
let array = Utf8Array::<i32>::from_trusted_len_values_iter(
std::iter::repeat("aaa")
.take(size / 2)
.chain(std::iter::repeat("bbb").take(size / 2)),
);
c.bench_function(&format!("iter_values 2^{log2_size}"), |b| {
b.iter(|| {
for x in array.values_iter() {
assert_eq!(x.len(), 3);
}
})
});
c.bench_function(&format!("iter 2^{log2_size}"), |b| {
b.iter(|| {
for x in array.iter() {
assert_eq!(x.unwrap().len(), 3);
}
})
});
})
}
criterion_group!(benches, add_benchmark);
criterion_main!(benches);