Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Updated bench
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Feb 27, 2022
1 parent 11f88b8 commit 1539556
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions benches/write_json.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,44 @@
use std::sync::Arc;

use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::array::*;
use arrow2::chunk::Chunk;
use arrow2::error::Result;
use arrow2::error::ArrowError;
use arrow2::io::json::write;
use arrow2::util::bench_util::*;

fn write_batch(columns: &Chunk<Arc<dyn Array>>) -> Result<()> {
fn write_array(array: Box<dyn Array>) -> Result<(), ArrowError> {
let mut writer = vec![];
let format = write::Format::Json;

let batches = vec![Ok(columns.clone())].into_iter();
let arrays = vec![Ok(array)].into_iter();

// Advancing this iterator serializes the next batch to its internal buffer (i.e. CPU-bounded)
let blocks = write::Serializer::new(batches, vec!["c1".to_string()], vec![], format);
// 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, format, blocks)?;
write::write(&mut writer, blocks)?;

Ok(())
}

fn make_chunk(array: impl Array + 'static) -> Chunk<Arc<dyn Array>> {
Chunk::new(vec![Arc::new(array) as Arc<dyn Array>])
}

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);
let columns = make_chunk(array);

c.bench_function(&format!("json write i32 2^{}", log2_size), |b| {
b.iter(|| write_batch(&columns))
b.iter(|| write_array(Box::new(array.clone())))
});

let array = create_string_array::<i32>(size, 100, 0.1, 42);
let columns = make_chunk(array);

c.bench_function(&format!("json write utf8 2^{}", log2_size), |b| {
b.iter(|| write_batch(&columns))
b.iter(|| write_array(Box::new(array.clone())))
});

let array = create_primitive_array::<f64>(size, 0.1);
let columns = make_chunk(array);

c.bench_function(&format!("json write f64 2^{}", log2_size), |b| {
b.iter(|| write_batch(&columns))
b.iter(|| write_array(Box::new(array.clone())))
});
});
}
Expand Down

0 comments on commit 1539556

Please sign in to comment.