friendlymatthew commented on code in PR #7808:
URL: https://github.com/apache/arrow-rs/pull/7808#discussion_r2173760495


##########
parquet-variant/benches/builder.rs:
##########
@@ -0,0 +1,389 @@
+// 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.
+
+extern crate parquet_variant;
+
+use criterion::*;
+
+use parquet_variant::VariantBuilder;
+use rand::{
+    distr::{uniform::SampleUniform, Alphanumeric},
+    rngs::ThreadRng,
+    Rng,
+};
+use std::{hint, ops::Range};
+
+fn random<T: SampleUniform + PartialEq + PartialOrd>(rng: &mut ThreadRng, 
range: Range<T>) -> T {
+    rng.random_range::<T, _>(range)
+}
+
+// generates a string with a 50/50 chance whether it's a short or a long string
+fn random_string(rng: &mut ThreadRng) -> String {
+    let len = rng.random_range::<usize, _>(1..128);
+
+    rng.sample_iter(&Alphanumeric)
+        .take(len)
+        .map(char::from)
+        .collect()
+}
+
+// generates a string guaranteed to be longer than 64 bytes
+fn random_long_string(rng: &mut ThreadRng) -> String {
+    let len = rng.random_range::<usize, _>(65..200);
+
+    rng.sample_iter(&Alphanumeric)
+        .take(len)
+        .map(char::from)
+        .collect()
+}
+
+// Creates an object with field names inserted in reverse lexicographical order
+fn bench_object_field_names_reverse_order(c: &mut Criterion) {
+    c.bench_function("bench_object_field_names_reverse_order", |b| {
+        b.iter(|| {
+            let mut rng = rand::rng();
+
+            let mut variant = VariantBuilder::new();
+            let mut object_builder = variant.new_object();
+
+            for i in 0..50_000 {
+                object_builder.insert(
+                    format!("{}", 1000 - i).as_str(),
+                    random_string(&mut rng).as_str(),
+                );
+            }
+
+            object_builder.finish();
+            hint::black_box(variant.finish());
+        })
+    });
+}
+
+// Creates objects with a homogenous schema (same field names)
+/*
+    {
+        name: String,
+        age: i32,
+        likes_cilantro: bool,
+        comments: Long string
+        dishes: Vec<String>
+    }
+*/
+fn bench_object_same_schema(c: &mut Criterion) {
+    c.bench_function("bench_object_same_schema", |b| {
+        b.iter(|| {
+            let mut rng = rand::rng();
+
+            for _ in 0..25_000 {
+                let mut variant = VariantBuilder::new();
+                let mut object_builder = variant.new_object();
+                object_builder.insert("name", random_string(&mut 
rng).as_str());
+                object_builder.insert("age", random::<u32>(&mut rng, 18..100) 
as i32);
+                object_builder.insert("likes_cilantro", rng.random_bool(0.5));
+                object_builder.insert("comments", random_long_string(&mut 
rng).as_str());
+
+                let mut inner_list_builder = object_builder.new_list("dishes");
+                inner_list_builder.append_value(random_string(&mut 
rng).as_str());
+                inner_list_builder.append_value(random_string(&mut 
rng).as_str());
+                inner_list_builder.append_value(random_string(&mut 
rng).as_str());
+
+                inner_list_builder.finish();
+                object_builder.finish();
+
+                hint::black_box(variant.finish());
+            }
+        })
+    });
+}
+
+// Creates a list of objects with the same schema (same field names)
+/*
+    {
+        name: String,
+        age: i32,
+        likes_cilantro: bool,
+        comments: Long string
+        dishes: Vec<String>
+    }
+*/
+fn bench_object_list_same_schema(c: &mut Criterion) {
+    c.bench_function("bench_object_list_same_schema", |b| {
+        b.iter(|| {
+            let mut rng = rand::rng();
+
+            let mut variant = VariantBuilder::new();
+
+            let mut list_builder = variant.new_list();
+
+            for _ in 0..25_000 {

Review Comment:
   That makes sense. My recent commit generates a string table ahead of time. 
Verified with my own profile 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-unsubscr...@arrow.apache.org

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

Reply via email to