alamb commented on code in PR #7944:
URL: https://github.com/apache/arrow-rs/pull/7944#discussion_r2211577187


##########
parquet-variant-compute/benches/variant_kernels.rs:
##########
@@ -0,0 +1,237 @@
+// 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.
+
+use arrow::array::{ArrayRef, StringArray};
+use arrow::util::test_util::seedable_rng;
+use criterion::{criterion_group, criterion_main, Criterion};
+use parquet_variant::{Variant, VariantBuilder};
+use parquet_variant_compute::variant_get::{variant_get, GetOptions};
+use parquet_variant_compute::{batch_json_string_to_variant, VariantArray, 
VariantArrayBuilder};
+use rand::distr::Alphanumeric;
+use rand::rngs::StdRng;
+use rand::Rng;
+use rand::SeedableRng;
+use std::fmt::Write;
+use std::sync::Arc;
+
+/// This function generates a vector of JSON strings, each representing a 
person
+/// with random first name, last name, and age.
+///
+/// Example:
+/// ```json
+/// {
+///   "first" : random_string_of_1_to_20_characters,
+///   "last" : random_string_of_1_to_20_characters,
+///   "age": random_value_between_20_and_80,
+/// }
+/// ```
+fn small_repeated_json_structure(count: usize) -> impl Iterator<Item = String> 
{
+    let mut rng = seedable_rng();
+    (0..count).map(move |_| {
+        let first: String = (0..rng.random_range(1..=20))
+            .map(|_| rng.sample(Alphanumeric) as char)
+            .collect();
+        let last: String = (0..rng.random_range(1..=20))
+            .map(|_| rng.sample(Alphanumeric) as char)
+            .collect();
+        let age: u8 = rng.random_range(20..=80);
+        format!("{{\"first\":\"{first}\",\"last\":\"{last}\",\"age\":{age}}}")
+    })
+}
+
+/// This function generates a vector of JSON strings which have many fields
+/// and a random structure (including field names)
+fn small_random_json_structure(count: usize) -> impl Iterator<Item = String> {
+    let mut generator = RandomJsonGenerator::new();
+    (0..count).map(move |_| generator.next().to_string())
+}
+
+fn benchmark_batch_json_string_to_variant(c: &mut Criterion) {
+    let input_array = 
StringArray::from_iter_values(small_repeated_json_structure(8000));
+    let array_ref: ArrayRef = Arc::new(input_array);
+    c.bench_function(
+        "batch_json_string_to_variant small_repeated_json 8k string",
+        |b| {
+            b.iter(|| {
+                let _ = batch_json_string_to_variant(&array_ref).unwrap();
+            });
+        },
+    );
+
+    let input_array = 
StringArray::from_iter_values(small_random_json_structure(8000));
+    let array_ref: ArrayRef = Arc::new(input_array);
+    c.bench_function(
+        "batch_json_string_to_variant small_random_json 8k string",
+        |b| {
+            b.iter(|| {
+                let _ = batch_json_string_to_variant(&array_ref).unwrap();
+            });
+        },
+    );
+}
+
+fn create_primitive_variant(size: usize) -> VariantArray {
+    let mut rng = StdRng::seed_from_u64(42);
+
+    let mut variant_builder = VariantArrayBuilder::new(1);
+
+    for _ in 0..size {
+        let mut builder = VariantBuilder::new();
+        builder.append_value(rng.random::<i64>());
+        let (metadata, value) = builder.finish();
+        variant_builder.append_variant(Variant::try_new(&metadata, 
&value).unwrap());
+    }
+
+    variant_builder.build()
+}
+
+pub fn variant_get_bench(c: &mut Criterion) {

Review Comment:
   variant_get benchmark is moved without modification here



-- 
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-unsubscr...@arrow.apache.org

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

Reply via email to