sdf-jkl commented on code in PR #10879:
URL: https://github.com/apache/arrow-rs/pull/10879#discussion_r3876728949


##########
parquet-variant/benches/variant_validation.rs:
##########
@@ -126,11 +154,99 @@ fn bench_validate_large_nested_list(c: &mut Criterion) {
     });
 }
 
+// The benchmarks below read field names back out of already-validated 
metadata, the path that
+// runs once per object field access. Validation is paid once, outside the 
measured loop.
+
+fn bench_metadata_iter(c: &mut Criterion) {
+    let mut group = c.benchmark_group("metadata_iter");
+    for n in [8usize, 32, 128] {
+        let names = field_names(n);
+        let (metadata, _value) = generate_object_with_field_names(&names);
+        let metadata = VariantMetadata::try_new(&metadata).unwrap();
+        group.throughput(Throughput::Elements(n as u64));
+        group.bench_function(BenchmarkId::from_parameter(n), |b| {
+            b.iter(|| {
+                let mut acc = 0usize;
+                for name in metadata.iter() {
+                    acc += std::hint::black_box(name).len();
+                }
+                std::hint::black_box(acc)
+            });
+        });
+    }
+    group.finish();
+}
+
+fn bench_object_field_name(c: &mut Criterion) {
+    let mut group = c.benchmark_group("object_field_name");
+    for n in [8usize, 32, 128] {
+        let names = field_names(n);
+        let (metadata, value) = generate_object_with_field_names(&names);
+        let metadata = VariantMetadata::try_new(&metadata).unwrap();
+        let variant = Variant::try_new_with_metadata(metadata, 
&value).unwrap();
+        let object = variant.as_object().unwrap();
+        group.throughput(Throughput::Elements(n as u64));
+        group.bench_function(BenchmarkId::from_parameter(n), |b| {
+            b.iter(|| {
+                let mut acc = 0usize;
+                for i in 0..n {
+                    acc += 
std::hint::black_box(object.field_name(i).unwrap()).len();
+                }
+                std::hint::black_box(acc)
+            });
+        });
+    }
+    group.finish();
+}
+
+fn bench_object_iter(c: &mut Criterion) {
+    let mut group = c.benchmark_group("object_iter");
+    for n in [8usize, 32, 128] {
+        let names = field_names(n);
+        let (metadata, value) = generate_object_with_field_names(&names);
+        let metadata = VariantMetadata::try_new(&metadata).unwrap();
+        let variant = Variant::try_new_with_metadata(metadata, 
&value).unwrap();
+        let object = variant.as_object().unwrap();
+        group.throughput(Throughput::Elements(n as u64));
+        group.bench_function(BenchmarkId::from_parameter(n), |b| {
+            b.iter(|| {
+                let mut acc = 0usize;
+                for (name, _value) in object.iter() {
+                    acc += std::hint::black_box(name).len();
+                }
+                std::hint::black_box(acc)
+            });
+        });
+    }
+    group.finish();
+}
+
+fn bench_object_get_by_name(c: &mut Criterion) {
+    let mut group = c.benchmark_group("object_get_by_name");
+    for n in [8usize, 32, 128] {
+        let names = field_names(n);
+        let (metadata, value) = generate_object_with_field_names(&names);
+        let metadata = VariantMetadata::try_new(&metadata).unwrap();
+        let variant = Variant::try_new_with_metadata(metadata, 
&value).unwrap();
+        let object = variant.as_object().unwrap();
+        // Always look up the last key, the worst case for a linear scan.

Review Comment:
   Spacing :facepalm: my bad



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to