This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7014e28
commit 696f915
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use arrow2::array::Array; | ||
use arrow2::datatypes::DataType; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use arrow2::io::json::{read, write}; | ||
use arrow2::util::bench_util::*; | ||
|
||
fn prep(array: impl Array + 'static) -> (Vec<u8>, DataType) { | ||
let mut data = vec![]; | ||
let blocks = write::Serializer::new( | ||
vec![Ok(Box::new(array) as Box<dyn Array>)].into_iter(), | ||
vec![], | ||
); | ||
// the operation of writing is IO-bounded. | ||
write::write(&mut data, blocks).unwrap(); | ||
|
||
let dt = read::infer(&serde_json::from_slice(&data).unwrap()).unwrap(); | ||
(data, dt) | ||
} | ||
|
||
fn bench_read(data: &[u8], dt: &DataType) { | ||
let json = serde_json::from_slice(data).unwrap(); | ||
read::deserialize(&json, dt.clone()).unwrap(); | ||
} | ||
|
||
fn add_benchmark(c: &mut Criterion) { | ||
(10..=20).step_by(2).for_each(|log2_size| { | ||
let size = 2usize.pow(log2_size); | ||
|
||
let array = create_primitive_array::<i32>(size, 0.1); | ||
|
||
let (data, dt) = prep(array); | ||
|
||
c.bench_function(&format!("read i32 2^{}", log2_size), |b| { | ||
b.iter(|| bench_read(&data, &dt)) | ||
}); | ||
|
||
let array = create_primitive_array::<f64>(size, 0.1); | ||
|
||
let (data, dt) = prep(array); | ||
|
||
c.bench_function(&format!("read f64 2^{}", log2_size), |b| { | ||
b.iter(|| bench_read(&data, &dt)) | ||
}); | ||
|
||
let array = create_string_array::<i32>(size, 10, 0.1, 42); | ||
|
||
let (data, dt) = prep(array); | ||
|
||
c.bench_function(&format!("read utf8 2^{}", log2_size), |b| { | ||
b.iter(|| bench_read(&data, &dt)) | ||
}); | ||
|
||
let array = create_boolean_array(size, 0.1, 0.1); | ||
|
||
let (data, dt) = prep(array); | ||
|
||
c.bench_function(&format!("read bool 2^{}", log2_size), |b| { | ||
b.iter(|| bench_read(&data, &dt)) | ||
}); | ||
}) | ||
} | ||
|
||
criterion_group!(benches, add_benchmark); | ||
criterion_main!(benches); |