MCPcopy Create free account
hub / github.com/apache/arrow-rs / criterion_benchmark

Function criterion_benchmark

arrow-array/benches/boolean_array.rs:22–74  ·  view source on GitHub ↗
(c: &mut Criterion)

Source from the content-addressed store, hash-verified

20use std::hint;
21
22fn criterion_benchmark(c: &mut Criterion) {
23 for len in [64, 1024, 65536] {
24 // All true (no nulls)
25 let all_true = BooleanArray::from(vec![true; len]);
26 c.bench_function(&format!("true_count(all_true, {len})"), |b| {
27 b.iter(|| hint::black_box(&all_true).true_count());
28 });
29 c.bench_function(&format!("has_true(all_true, {len})"), |b| {
30 b.iter(|| hint::black_box(&all_true).has_true());
31 });
32 c.bench_function(&format!("has_false(all_true, {len})"), |b| {
33 b.iter(|| hint::black_box(&all_true).has_false());
34 });
35
36 // All false (no nulls)
37 let all_false = BooleanArray::from(vec![false; len]);
38 c.bench_function(&format!("true_count(all_false, {len})"), |b| {
39 b.iter(|| hint::black_box(&all_false).true_count());
40 });
41 c.bench_function(&format!("has_true(all_false, {len})"), |b| {
42 b.iter(|| hint::black_box(&all_false).has_true());
43 });
44 c.bench_function(&format!("has_false(all_false, {len})"), |b| {
45 b.iter(|| hint::black_box(&all_false).has_false());
46 });
47
48 // Mixed: first element differs (best-case short-circuit)
49 let mut mixed_early: Vec<bool> = vec![true; len];
50 mixed_early[0] = false;
51 let mixed_early = BooleanArray::from(mixed_early);
52 c.bench_function(&format!("true_count(mixed_early, {len})"), |b| {
53 b.iter(|| hint::black_box(&mixed_early).true_count());
54 });
55 c.bench_function(&format!("has_false(mixed_early, {len})"), |b| {
56 b.iter(|| hint::black_box(&mixed_early).has_false());
57 });
58
59 // With nulls: all valid values true
60 let with_nulls: Vec<Option<bool>> = (0..len)
61 .map(|i| if i % 10 == 0 { None } else { Some(true) })
62 .collect();
63 let with_nulls = BooleanArray::from(with_nulls);
64 c.bench_function(&format!("true_count(nulls_all_true, {len})"), |b| {
65 b.iter(|| hint::black_box(&with_nulls).true_count());
66 });
67 c.bench_function(&format!("has_true(nulls_all_true, {len})"), |b| {
68 b.iter(|| hint::black_box(&with_nulls).has_true());
69 });
70 c.bench_function(&format!("has_false(nulls_all_true, {len})"), |b| {
71 b.iter(|| hint::black_box(&with_nulls).has_false());
72 });
73 }
74}
75
76criterion_group!(benches, criterion_benchmark);
77criterion_main!(benches);

Callers

nothing calls this directly

Calls 5

true_countMethod · 0.80
collectMethod · 0.80
iterMethod · 0.45
has_trueMethod · 0.45
has_falseMethod · 0.45

Tested by

no test coverage detected