You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jecsand838 (via GitHub)" <gi...@apache.org> on 2025/08/18 18:47:13 UTC

[PR] Add benchmarks for arrow-avro writer [arrow-rs]

jecsand838 opened a new pull request, #8165:
URL: https://github.com/apache/arrow-rs/pull/8165

   # Which issue does this PR close?
   
   - Part of https://github.com/apache/arrow-rs/issues/4886
   
   # Rationale for this change
   
   This PR introduces benchmark tests for the `AvroWriter` in the `arrow-avro` crate. Adding these benchmarks is essential for tracking the performance of the writer, identifying potential regressions, and guiding future optimizations.
   
   # What changes are included in this PR?
   
   A new benchmark file, `benches/avro_writer.rs`, is added to the project. This file contains a suite of benchmarks that measure the performance of writing `RecordBatch`es to the Avro format.
   
   The benchmarks cover a variety of Arrow data types:
   - `Boolean`
   - `Int32` and `Int64`
   - `Float32` and `Float64`
   - `Binary`
   - `Timestamp` (Microsecond precision)
   - A schema with a mix of the above types
   
   These benchmarks are run with varying numbers of rows (100, 10,000, and 1,000,000) to assess performance across different data scales.
   
   # Are these changes tested?
   
   Yes, this pull request consists entirely of new benchmark tests. Therefore, no separate tests are needed.
   
   # Are there any user-facing changes?
   
   NA


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "jecsand838 (via GitHub)" <gi...@apache.org>.
jecsand838 commented on code in PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#discussion_r2294432502


##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {
+    BooleanArray::from_iter((0..n).map(|i| Some(i % 2 == 0)))
+}
+
+fn make_i32_array(n: usize) -> PrimitiveArray<Int32Type> {
+    PrimitiveArray::<Int32Type>::from_iter_values((0..n).map(|i| i as i32))
+}
+
+fn make_i64_array(n: usize) -> PrimitiveArray<Int64Type> {
+    PrimitiveArray::<Int64Type>::from_iter_values((0..n).map(|i| i as i64))
+}
+
+fn make_f32_array(n: usize) -> Float32Array {
+    Float32Array::from_iter_values((0..n).map(|i| i as f32 + 0.5678))
+}
+
+fn make_f64_array(n: usize) -> Float64Array {
+    Float64Array::from_iter_values((0..n).map(|i| i as f64 + 0.1234))
+}
+
+fn make_binary_array(n: usize) -> BinaryArray {
+    let payloads: Vec<Vec<u8>> = (0..n).map(|i| vec![(i & 0xFF) as u8; 16]).collect();
+    let views: Vec<&[u8]> = payloads.iter().map(|v| v.as_slice()).collect();
+    BinaryArray::from_vec(views)
+}
+
+fn make_ts_micros_array(n: usize) -> PrimitiveArray<TimestampMicrosecondType> {
+    let base: i64 = 1_600_000_000_000_000;
+    PrimitiveArray::<TimestampMicrosecondType>::from_iter_values((0..n).map(|i| base + i as i64))
+}
+
+fn schema_single(name: &str, dt: DataType) -> Arc<Schema> {
+    Arc::new(Schema::new(vec![Field::new(name, dt, false)]))
+}
+
+fn schema_mixed() -> Arc<Schema> {
+    Arc::new(Schema::new(vec![
+        Field::new("f1", DataType::Int32, false),
+        Field::new("f2", DataType::Int64, false),
+        Field::new("f3", DataType::Binary, false),
+        Field::new("f4", DataType::Float64, false),
+    ]))
+}
+
+static BOOLEAN_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Boolean);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_bool_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static BINARY_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Binary);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_binary_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static TIMESTAMP_US_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Timestamp(TimeUnit::Microsecond, None));
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_ts_micros_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static MIXED_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_mixed();
+    SIZES
+        .iter()
+        .map(|&n| {
+            let f1: ArrayRef = Arc::new(make_i32_array(n));
+            let f2: ArrayRef = Arc::new(make_i64_array(n));
+            let f3: ArrayRef = Arc::new(make_binary_array(n));
+            let f4: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![f1, f2, f3, f4]).unwrap()
+        })
+        .collect()
+});
+
+fn ocf_size_for_batch(batch: &RecordBatch) -> usize {
+    let schema_owned: Schema = (*batch.schema()).clone();
+    let cursor = Cursor::new(Vec::<u8>::with_capacity(1024));
+    let mut writer = AvroWriter::new(cursor, schema_owned).expect("create writer");
+    writer.write(batch).expect("write batch");
+    writer.finish().expect("finish writer");
+    let inner = writer.into_inner();
+    inner.into_inner().len()
+}
+
+fn bench_writer_scenario(c: &mut Criterion, name: &str, data_sets: &[RecordBatch]) {
+    let mut group = c.benchmark_group(name);
+    let schema_owned: Schema = (*data_sets[0].schema()).clone();
+    for (idx, &rows) in SIZES.iter().enumerate() {
+        let batch = &data_sets[idx];
+        let bytes = ocf_size_for_batch(batch);
+        group.throughput(Throughput::Bytes(bytes as u64));
+        match rows {
+            10_000 => {

Review Comment:
   Pushed these changes up as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "jecsand838 (via GitHub)" <gi...@apache.org>.
jecsand838 commented on code in PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#discussion_r2294634188


##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {
+    BooleanArray::from_iter((0..n).map(|i| Some(i % 2 == 0)))
+}
+
+fn make_i32_array(n: usize) -> PrimitiveArray<Int32Type> {
+    PrimitiveArray::<Int32Type>::from_iter_values((0..n).map(|i| i as i32))
+}
+
+fn make_i64_array(n: usize) -> PrimitiveArray<Int64Type> {
+    PrimitiveArray::<Int64Type>::from_iter_values((0..n).map(|i| i as i64))
+}
+
+fn make_f32_array(n: usize) -> Float32Array {
+    Float32Array::from_iter_values((0..n).map(|i| i as f32 + 0.5678))
+}
+
+fn make_f64_array(n: usize) -> Float64Array {
+    Float64Array::from_iter_values((0..n).map(|i| i as f64 + 0.1234))
+}
+
+fn make_binary_array(n: usize) -> BinaryArray {
+    let payloads: Vec<Vec<u8>> = (0..n).map(|i| vec![(i & 0xFF) as u8; 16]).collect();
+    let views: Vec<&[u8]> = payloads.iter().map(|v| v.as_slice()).collect();
+    BinaryArray::from_vec(views)
+}
+
+fn make_ts_micros_array(n: usize) -> PrimitiveArray<TimestampMicrosecondType> {
+    let base: i64 = 1_600_000_000_000_000;
+    PrimitiveArray::<TimestampMicrosecondType>::from_iter_values((0..n).map(|i| base + i as i64))
+}
+
+fn schema_single(name: &str, dt: DataType) -> Arc<Schema> {
+    Arc::new(Schema::new(vec![Field::new(name, dt, false)]))
+}
+
+fn schema_mixed() -> Arc<Schema> {
+    Arc::new(Schema::new(vec![
+        Field::new("f1", DataType::Int32, false),
+        Field::new("f2", DataType::Int64, false),
+        Field::new("f3", DataType::Binary, false),
+        Field::new("f4", DataType::Float64, false),
+    ]))
+}
+
+static BOOLEAN_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Boolean);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_bool_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static BINARY_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Binary);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_binary_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static TIMESTAMP_US_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Timestamp(TimeUnit::Microsecond, None));
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_ts_micros_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static MIXED_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_mixed();
+    SIZES
+        .iter()
+        .map(|&n| {
+            let f1: ArrayRef = Arc::new(make_i32_array(n));
+            let f2: ArrayRef = Arc::new(make_i64_array(n));
+            let f3: ArrayRef = Arc::new(make_binary_array(n));
+            let f4: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![f1, f2, f3, f4]).unwrap()
+        })
+        .collect()
+});
+
+fn ocf_size_for_batch(batch: &RecordBatch) -> usize {

Review Comment:
   Also to be a bit more clear, my intention here was to feed this `usize` byte count value into `Throughput::Bytes()` so Criterion reports MB/s for actual on‑disk OCF bytes written per iteration.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "jecsand838 (via GitHub)" <gi...@apache.org>.
jecsand838 commented on code in PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#discussion_r2292161871


##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {
+    BooleanArray::from_iter((0..n).map(|i| Some(i % 2 == 0)))
+}
+
+fn make_i32_array(n: usize) -> PrimitiveArray<Int32Type> {
+    PrimitiveArray::<Int32Type>::from_iter_values((0..n).map(|i| i as i32))
+}
+
+fn make_i64_array(n: usize) -> PrimitiveArray<Int64Type> {
+    PrimitiveArray::<Int64Type>::from_iter_values((0..n).map(|i| i as i64))
+}
+
+fn make_f32_array(n: usize) -> Float32Array {
+    Float32Array::from_iter_values((0..n).map(|i| i as f32 + 0.5678))
+}
+
+fn make_f64_array(n: usize) -> Float64Array {
+    Float64Array::from_iter_values((0..n).map(|i| i as f64 + 0.1234))
+}
+
+fn make_binary_array(n: usize) -> BinaryArray {
+    let payloads: Vec<Vec<u8>> = (0..n).map(|i| vec![(i & 0xFF) as u8; 16]).collect();
+    let views: Vec<&[u8]> = payloads.iter().map(|v| v.as_slice()).collect();
+    BinaryArray::from_vec(views)
+}
+
+fn make_ts_micros_array(n: usize) -> PrimitiveArray<TimestampMicrosecondType> {
+    let base: i64 = 1_600_000_000_000_000;
+    PrimitiveArray::<TimestampMicrosecondType>::from_iter_values((0..n).map(|i| base + i as i64))
+}
+
+fn schema_single(name: &str, dt: DataType) -> Arc<Schema> {
+    Arc::new(Schema::new(vec![Field::new(name, dt, false)]))
+}
+
+fn schema_mixed() -> Arc<Schema> {
+    Arc::new(Schema::new(vec![
+        Field::new("f1", DataType::Int32, false),
+        Field::new("f2", DataType::Int64, false),
+        Field::new("f3", DataType::Binary, false),
+        Field::new("f4", DataType::Float64, false),
+    ]))
+}
+
+static BOOLEAN_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Boolean);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_bool_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static BINARY_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Binary);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_binary_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static TIMESTAMP_US_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Timestamp(TimeUnit::Microsecond, None));
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_ts_micros_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static MIXED_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_mixed();
+    SIZES
+        .iter()
+        .map(|&n| {
+            let f1: ArrayRef = Arc::new(make_i32_array(n));
+            let f2: ArrayRef = Arc::new(make_i64_array(n));
+            let f3: ArrayRef = Arc::new(make_binary_array(n));
+            let f4: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![f1, f2, f3, f4]).unwrap()
+        })
+        .collect()
+});
+
+fn ocf_size_for_batch(batch: &RecordBatch) -> usize {

Review Comment:
   It's the size of the Avro Object Container File. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "jecsand838 (via GitHub)" <gi...@apache.org>.
jecsand838 commented on code in PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#discussion_r2292160598


##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {

Review Comment:
   Ah that makes sense. I can add that in tonight.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "jecsand838 (via GitHub)" <gi...@apache.org>.
jecsand838 commented on code in PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#discussion_r2292163077


##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {
+    BooleanArray::from_iter((0..n).map(|i| Some(i % 2 == 0)))
+}
+
+fn make_i32_array(n: usize) -> PrimitiveArray<Int32Type> {
+    PrimitiveArray::<Int32Type>::from_iter_values((0..n).map(|i| i as i32))
+}
+
+fn make_i64_array(n: usize) -> PrimitiveArray<Int64Type> {
+    PrimitiveArray::<Int64Type>::from_iter_values((0..n).map(|i| i as i64))
+}
+
+fn make_f32_array(n: usize) -> Float32Array {
+    Float32Array::from_iter_values((0..n).map(|i| i as f32 + 0.5678))
+}
+
+fn make_f64_array(n: usize) -> Float64Array {
+    Float64Array::from_iter_values((0..n).map(|i| i as f64 + 0.1234))
+}
+
+fn make_binary_array(n: usize) -> BinaryArray {
+    let payloads: Vec<Vec<u8>> = (0..n).map(|i| vec![(i & 0xFF) as u8; 16]).collect();
+    let views: Vec<&[u8]> = payloads.iter().map(|v| v.as_slice()).collect();
+    BinaryArray::from_vec(views)
+}
+
+fn make_ts_micros_array(n: usize) -> PrimitiveArray<TimestampMicrosecondType> {
+    let base: i64 = 1_600_000_000_000_000;
+    PrimitiveArray::<TimestampMicrosecondType>::from_iter_values((0..n).map(|i| base + i as i64))
+}
+
+fn schema_single(name: &str, dt: DataType) -> Arc<Schema> {
+    Arc::new(Schema::new(vec![Field::new(name, dt, false)]))
+}
+
+fn schema_mixed() -> Arc<Schema> {
+    Arc::new(Schema::new(vec![
+        Field::new("f1", DataType::Int32, false),
+        Field::new("f2", DataType::Int64, false),
+        Field::new("f3", DataType::Binary, false),
+        Field::new("f4", DataType::Float64, false),
+    ]))
+}
+
+static BOOLEAN_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Boolean);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_bool_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static BINARY_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Binary);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_binary_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static TIMESTAMP_US_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Timestamp(TimeUnit::Microsecond, None));
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_ts_micros_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static MIXED_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_mixed();
+    SIZES
+        .iter()
+        .map(|&n| {
+            let f1: ArrayRef = Arc::new(make_i32_array(n));
+            let f2: ArrayRef = Arc::new(make_i64_array(n));
+            let f3: ArrayRef = Arc::new(make_binary_array(n));
+            let f4: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![f1, f2, f3, f4]).unwrap()
+        })
+        .collect()
+});
+
+fn ocf_size_for_batch(batch: &RecordBatch) -> usize {
+    let schema_owned: Schema = (*batch.schema()).clone();
+    let cursor = Cursor::new(Vec::<u8>::with_capacity(1024));
+    let mut writer = AvroWriter::new(cursor, schema_owned).expect("create writer");
+    writer.write(batch).expect("write batch");
+    writer.finish().expect("finish writer");
+    let inner = writer.into_inner();
+    inner.into_inner().len()
+}
+
+fn bench_writer_scenario(c: &mut Criterion, name: &str, data_sets: &[RecordBatch]) {
+    let mut group = c.benchmark_group(name);
+    let schema_owned: Schema = (*data_sets[0].schema()).clone();
+    for (idx, &rows) in SIZES.iter().enumerate() {
+        let batch = &data_sets[idx];
+        let bytes = ocf_size_for_batch(batch);
+        group.throughput(Throughput::Bytes(bytes as u64));
+        match rows {
+            10_000 => {

Review Comment:
   That's a good call out. I'll push those changes up tonight as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "jecsand838 (via GitHub)" <gi...@apache.org>.
jecsand838 commented on code in PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#discussion_r2292161871


##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {
+    BooleanArray::from_iter((0..n).map(|i| Some(i % 2 == 0)))
+}
+
+fn make_i32_array(n: usize) -> PrimitiveArray<Int32Type> {
+    PrimitiveArray::<Int32Type>::from_iter_values((0..n).map(|i| i as i32))
+}
+
+fn make_i64_array(n: usize) -> PrimitiveArray<Int64Type> {
+    PrimitiveArray::<Int64Type>::from_iter_values((0..n).map(|i| i as i64))
+}
+
+fn make_f32_array(n: usize) -> Float32Array {
+    Float32Array::from_iter_values((0..n).map(|i| i as f32 + 0.5678))
+}
+
+fn make_f64_array(n: usize) -> Float64Array {
+    Float64Array::from_iter_values((0..n).map(|i| i as f64 + 0.1234))
+}
+
+fn make_binary_array(n: usize) -> BinaryArray {
+    let payloads: Vec<Vec<u8>> = (0..n).map(|i| vec![(i & 0xFF) as u8; 16]).collect();
+    let views: Vec<&[u8]> = payloads.iter().map(|v| v.as_slice()).collect();
+    BinaryArray::from_vec(views)
+}
+
+fn make_ts_micros_array(n: usize) -> PrimitiveArray<TimestampMicrosecondType> {
+    let base: i64 = 1_600_000_000_000_000;
+    PrimitiveArray::<TimestampMicrosecondType>::from_iter_values((0..n).map(|i| base + i as i64))
+}
+
+fn schema_single(name: &str, dt: DataType) -> Arc<Schema> {
+    Arc::new(Schema::new(vec![Field::new(name, dt, false)]))
+}
+
+fn schema_mixed() -> Arc<Schema> {
+    Arc::new(Schema::new(vec![
+        Field::new("f1", DataType::Int32, false),
+        Field::new("f2", DataType::Int64, false),
+        Field::new("f3", DataType::Binary, false),
+        Field::new("f4", DataType::Float64, false),
+    ]))
+}
+
+static BOOLEAN_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Boolean);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_bool_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static BINARY_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Binary);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_binary_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static TIMESTAMP_US_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Timestamp(TimeUnit::Microsecond, None));
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_ts_micros_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static MIXED_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_mixed();
+    SIZES
+        .iter()
+        .map(|&n| {
+            let f1: ArrayRef = Arc::new(make_i32_array(n));
+            let f2: ArrayRef = Arc::new(make_i64_array(n));
+            let f3: ArrayRef = Arc::new(make_binary_array(n));
+            let f4: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![f1, f2, f3, f4]).unwrap()
+        })
+        .collect()
+});
+
+fn ocf_size_for_batch(batch: &RecordBatch) -> usize {

Review Comment:
   Avro Object Container File. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "jecsand838 (via GitHub)" <gi...@apache.org>.
jecsand838 commented on code in PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#discussion_r2294432030


##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {

Review Comment:
   @alamb I just pushed up some changes based on your feedback regarding the random inputs. Let me know what you think!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#issuecomment-3216662738

   I took a look at the changes and they look good to me -- thanks @conradludgate 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add benchmarks for arrow-avro writer [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8165:
URL: https://github.com/apache/arrow-rs/pull/8165#discussion_r2291766602


##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {
+    BooleanArray::from_iter((0..n).map(|i| Some(i % 2 == 0)))
+}
+
+fn make_i32_array(n: usize) -> PrimitiveArray<Int32Type> {
+    PrimitiveArray::<Int32Type>::from_iter_values((0..n).map(|i| i as i32))
+}
+
+fn make_i64_array(n: usize) -> PrimitiveArray<Int64Type> {
+    PrimitiveArray::<Int64Type>::from_iter_values((0..n).map(|i| i as i64))
+}
+
+fn make_f32_array(n: usize) -> Float32Array {
+    Float32Array::from_iter_values((0..n).map(|i| i as f32 + 0.5678))
+}
+
+fn make_f64_array(n: usize) -> Float64Array {
+    Float64Array::from_iter_values((0..n).map(|i| i as f64 + 0.1234))
+}
+
+fn make_binary_array(n: usize) -> BinaryArray {
+    let payloads: Vec<Vec<u8>> = (0..n).map(|i| vec![(i & 0xFF) as u8; 16]).collect();
+    let views: Vec<&[u8]> = payloads.iter().map(|v| v.as_slice()).collect();
+    BinaryArray::from_vec(views)
+}
+
+fn make_ts_micros_array(n: usize) -> PrimitiveArray<TimestampMicrosecondType> {
+    let base: i64 = 1_600_000_000_000_000;
+    PrimitiveArray::<TimestampMicrosecondType>::from_iter_values((0..n).map(|i| base + i as i64))
+}
+
+fn schema_single(name: &str, dt: DataType) -> Arc<Schema> {
+    Arc::new(Schema::new(vec![Field::new(name, dt, false)]))
+}
+
+fn schema_mixed() -> Arc<Schema> {
+    Arc::new(Schema::new(vec![
+        Field::new("f1", DataType::Int32, false),
+        Field::new("f2", DataType::Int64, false),
+        Field::new("f3", DataType::Binary, false),
+        Field::new("f4", DataType::Float64, false),
+    ]))
+}
+
+static BOOLEAN_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Boolean);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_bool_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static BINARY_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Binary);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_binary_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static TIMESTAMP_US_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Timestamp(TimeUnit::Microsecond, None));
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_ts_micros_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static MIXED_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_mixed();
+    SIZES
+        .iter()
+        .map(|&n| {
+            let f1: ArrayRef = Arc::new(make_i32_array(n));
+            let f2: ArrayRef = Arc::new(make_i64_array(n));
+            let f3: ArrayRef = Arc::new(make_binary_array(n));
+            let f4: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![f1, f2, f3, f4]).unwrap()
+        })
+        .collect()
+});
+
+fn ocf_size_for_batch(batch: &RecordBatch) -> usize {
+    let schema_owned: Schema = (*batch.schema()).clone();
+    let cursor = Cursor::new(Vec::<u8>::with_capacity(1024));
+    let mut writer = AvroWriter::new(cursor, schema_owned).expect("create writer");
+    writer.write(batch).expect("write batch");
+    writer.finish().expect("finish writer");
+    let inner = writer.into_inner();
+    inner.into_inner().len()
+}
+
+fn bench_writer_scenario(c: &mut Criterion, name: &str, data_sets: &[RecordBatch]) {
+    let mut group = c.benchmark_group(name);
+    let schema_owned: Schema = (*data_sets[0].schema()).clone();
+    for (idx, &rows) in SIZES.iter().enumerate() {
+        let batch = &data_sets[idx];
+        let bytes = ocf_size_for_batch(batch);
+        group.throughput(Throughput::Bytes(bytes as u64));
+        match rows {
+            10_000 => {

Review Comment:
   A common batch size is 8k as well -- I might suggest testing 4k or 8k batches along with 100k to better represent any per-batch overhead (as with 100K it will be drowned out)



##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {

Review Comment:
   Most of our other benchmarks use random input to avoid pathalogical cases due to patterns in the input
   
   I recommend doing the same in this PR
   
   Here are some examples
   
   https://github.com/apache/arrow-rs/blob/a9b4221a5519e1e7a834ad809fff418864d33018/arrow/src/util/data_gen.rs#L37



##########
arrow-avro/benches/avro_writer.rs:
##########
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for `arrow‑avro` **Decoder**
+//!
+
+extern crate arrow_avro;
+extern crate criterion;
+extern crate once_cell;
+
+use arrow_array::{
+    types::{Int32Type, Int64Type, TimestampMicrosecondType},
+    ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, PrimitiveArray, RecordBatch,
+};
+use arrow_avro::writer::AvroWriter;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
+use once_cell::sync::Lazy;
+use std::io::Cursor;
+use std::sync::Arc;
+use std::time::Duration;
+use tempfile::tempfile;
+
+const SIZES: [usize; 3] = [100, 10_000, 1_000_000];
+
+fn make_bool_array(n: usize) -> BooleanArray {
+    BooleanArray::from_iter((0..n).map(|i| Some(i % 2 == 0)))
+}
+
+fn make_i32_array(n: usize) -> PrimitiveArray<Int32Type> {
+    PrimitiveArray::<Int32Type>::from_iter_values((0..n).map(|i| i as i32))
+}
+
+fn make_i64_array(n: usize) -> PrimitiveArray<Int64Type> {
+    PrimitiveArray::<Int64Type>::from_iter_values((0..n).map(|i| i as i64))
+}
+
+fn make_f32_array(n: usize) -> Float32Array {
+    Float32Array::from_iter_values((0..n).map(|i| i as f32 + 0.5678))
+}
+
+fn make_f64_array(n: usize) -> Float64Array {
+    Float64Array::from_iter_values((0..n).map(|i| i as f64 + 0.1234))
+}
+
+fn make_binary_array(n: usize) -> BinaryArray {
+    let payloads: Vec<Vec<u8>> = (0..n).map(|i| vec![(i & 0xFF) as u8; 16]).collect();
+    let views: Vec<&[u8]> = payloads.iter().map(|v| v.as_slice()).collect();
+    BinaryArray::from_vec(views)
+}
+
+fn make_ts_micros_array(n: usize) -> PrimitiveArray<TimestampMicrosecondType> {
+    let base: i64 = 1_600_000_000_000_000;
+    PrimitiveArray::<TimestampMicrosecondType>::from_iter_values((0..n).map(|i| base + i as i64))
+}
+
+fn schema_single(name: &str, dt: DataType) -> Arc<Schema> {
+    Arc::new(Schema::new(vec![Field::new(name, dt, false)]))
+}
+
+fn schema_mixed() -> Arc<Schema> {
+    Arc::new(Schema::new(vec![
+        Field::new("f1", DataType::Int32, false),
+        Field::new("f2", DataType::Int64, false),
+        Field::new("f3", DataType::Binary, false),
+        Field::new("f4", DataType::Float64, false),
+    ]))
+}
+
+static BOOLEAN_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Boolean);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_bool_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static INT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Int64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_i64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT32_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float32);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f32_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static FLOAT64_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Float64);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static BINARY_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Binary);
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_binary_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static TIMESTAMP_US_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_single("field1", DataType::Timestamp(TimeUnit::Microsecond, None));
+    SIZES
+        .iter()
+        .map(|&n| {
+            let col: ArrayRef = Arc::new(make_ts_micros_array(n));
+            RecordBatch::try_new(schema.clone(), vec![col]).unwrap()
+        })
+        .collect()
+});
+
+static MIXED_DATA: Lazy<Vec<RecordBatch>> = Lazy::new(|| {
+    let schema = schema_mixed();
+    SIZES
+        .iter()
+        .map(|&n| {
+            let f1: ArrayRef = Arc::new(make_i32_array(n));
+            let f2: ArrayRef = Arc::new(make_i64_array(n));
+            let f3: ArrayRef = Arc::new(make_binary_array(n));
+            let f4: ArrayRef = Arc::new(make_f64_array(n));
+            RecordBatch::try_new(schema.clone(), vec![f1, f2, f3, f4]).unwrap()
+        })
+        .collect()
+});
+
+fn ocf_size_for_batch(batch: &RecordBatch) -> usize {

Review Comment:
   What does OCF size mean?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org