forked from jorgecarleitao/arrow2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_json.rs
47 lines (33 loc) · 1.38 KB
/
write_json.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
35
36
37
38
39
40
41
42
43
44
45
46
47
use criterion::{criterion_group, criterion_main, Criterion};
use arrow2::array::*;
use arrow2::error::Error;
use arrow2::io::json::write;
use arrow2::util::bench_util::*;
fn write_array(array: Box<dyn Array>) -> Result<(), Error> {
let mut writer = vec![];
let arrays = vec![Ok(array)].into_iter();
// Advancing this iterator serializes the next array to its internal buffer (i.e. CPU-bounded)
let blocks = write::Serializer::new(arrays, vec![]);
// the operation of writing is IO-bounded.
write::write(&mut writer, blocks)?;
Ok(())
}
fn add_benchmark(c: &mut Criterion) {
(10..=18).step_by(2).for_each(|log2_size| {
let size = 2usize.pow(log2_size);
let array = create_primitive_array::<i32>(size, 0.1);
c.bench_function(&format!("json write i32 2^{log2_size}"), |b| {
b.iter(|| write_array(Box::new(array.clone())))
});
let array = create_string_array::<i32>(size, 100, 0.1, 42);
c.bench_function(&format!("json write utf8 2^{log2_size}"), |b| {
b.iter(|| write_array(Box::new(array.clone())))
});
let array = create_primitive_array::<f64>(size, 0.1);
c.bench_function(&format!("json write f64 2^{log2_size}"), |b| {
b.iter(|| write_array(Box::new(array.clone())))
});
});
}
criterion_group!(benches, add_benchmark);
criterion_main!(benches);