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 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved performance of deserializing JSON (2x) (#1024)
- Loading branch information
1 parent
459de25
commit b2b0bb6
Showing
17 changed files
with
411 additions
and
75 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,67 @@ | ||
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 value = read::json_deserializer::parse(&data).unwrap(); | ||
|
||
let dt = read::infer(&value).unwrap(); | ||
(data, dt) | ||
} | ||
|
||
fn bench_read(data: &[u8], dt: &DataType) { | ||
let value = read::json_deserializer::parse(data).unwrap(); | ||
read::deserialize(&value, 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); |
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
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
Oops, something went wrong.