|
3 | 3 |
|
4 | 4 | #![allow(clippy::unwrap_used, clippy::cast_possible_truncation)] |
5 | 5 |
|
| 6 | +use std::fmt; |
| 7 | + |
6 | 8 | use divan::Bencher; |
7 | 9 | use vortex_array::arrays::BoolArray; |
8 | 10 | use vortex_array::arrays::PrimitiveArray; |
@@ -32,6 +34,35 @@ enum BoolDistribution { |
32 | 34 | AllFalse, |
33 | 35 | } |
34 | 36 |
|
| 37 | +impl fmt::Display for BoolDistribution { |
| 38 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 39 | + match self { |
| 40 | + BoolDistribution::Alternating => write!(f, "alternating"), |
| 41 | + BoolDistribution::MostlyTrue => write!(f, "mostly_true"), |
| 42 | + BoolDistribution::MostlyFalse => write!(f, "mostly_false"), |
| 43 | + BoolDistribution::AllTrue => write!(f, "all_true"), |
| 44 | + BoolDistribution::AllFalse => write!(f, "all_false"), |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +#[derive(Clone, Copy)] |
| 50 | +struct BoolBenchArgs { |
| 51 | + total_length: usize, |
| 52 | + avg_run_length: usize, |
| 53 | + distribution: BoolDistribution, |
| 54 | +} |
| 55 | + |
| 56 | +impl fmt::Display for BoolBenchArgs { |
| 57 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 58 | + write!( |
| 59 | + f, |
| 60 | + "{}_{}_{}", |
| 61 | + self.total_length, self.avg_run_length, self.distribution |
| 62 | + ) |
| 63 | + } |
| 64 | +} |
| 65 | + |
35 | 66 | /// Creates bool test data with configurable distribution |
36 | 67 | fn create_bool_test_data( |
37 | 68 | total_length: usize, |
@@ -66,45 +97,121 @@ fn create_bool_test_data( |
66 | 97 | ) |
67 | 98 | } |
68 | 99 |
|
69 | | -// Medium size: 10k elements with various run lengths |
70 | | -const BOOL_ARGS: &[(usize, usize)] = &[ |
71 | | - (10_000, 2), // Very short runs (5000 runs) |
72 | | - (10_000, 10), // Short runs (1000 runs) |
73 | | - (10_000, 100), // Medium runs (100 runs) |
74 | | - (10_000, 1000), // Long runs (10 runs) |
| 100 | +// Medium size: 10k elements with various run lengths and distributions |
| 101 | +const BOOL_ARGS: &[BoolBenchArgs] = &[ |
| 102 | + BoolBenchArgs { |
| 103 | + total_length: 10_000, |
| 104 | + avg_run_length: 2, |
| 105 | + distribution: BoolDistribution::Alternating, |
| 106 | + }, |
| 107 | + BoolBenchArgs { |
| 108 | + total_length: 10_000, |
| 109 | + avg_run_length: 10, |
| 110 | + distribution: BoolDistribution::Alternating, |
| 111 | + }, |
| 112 | + BoolBenchArgs { |
| 113 | + total_length: 10_000, |
| 114 | + avg_run_length: 100, |
| 115 | + distribution: BoolDistribution::Alternating, |
| 116 | + }, |
| 117 | + BoolBenchArgs { |
| 118 | + total_length: 10_000, |
| 119 | + avg_run_length: 1000, |
| 120 | + distribution: BoolDistribution::Alternating, |
| 121 | + }, |
| 122 | + BoolBenchArgs { |
| 123 | + total_length: 10_000, |
| 124 | + avg_run_length: 2, |
| 125 | + distribution: BoolDistribution::MostlyTrue, |
| 126 | + }, |
| 127 | + BoolBenchArgs { |
| 128 | + total_length: 10_000, |
| 129 | + avg_run_length: 10, |
| 130 | + distribution: BoolDistribution::MostlyTrue, |
| 131 | + }, |
| 132 | + BoolBenchArgs { |
| 133 | + total_length: 10_000, |
| 134 | + avg_run_length: 100, |
| 135 | + distribution: BoolDistribution::MostlyTrue, |
| 136 | + }, |
| 137 | + BoolBenchArgs { |
| 138 | + total_length: 10_000, |
| 139 | + avg_run_length: 1000, |
| 140 | + distribution: BoolDistribution::MostlyTrue, |
| 141 | + }, |
| 142 | + BoolBenchArgs { |
| 143 | + total_length: 10_000, |
| 144 | + avg_run_length: 2, |
| 145 | + distribution: BoolDistribution::MostlyFalse, |
| 146 | + }, |
| 147 | + BoolBenchArgs { |
| 148 | + total_length: 10_000, |
| 149 | + avg_run_length: 10, |
| 150 | + distribution: BoolDistribution::MostlyFalse, |
| 151 | + }, |
| 152 | + BoolBenchArgs { |
| 153 | + total_length: 10_000, |
| 154 | + avg_run_length: 100, |
| 155 | + distribution: BoolDistribution::MostlyFalse, |
| 156 | + }, |
| 157 | + BoolBenchArgs { |
| 158 | + total_length: 10_000, |
| 159 | + avg_run_length: 1000, |
| 160 | + distribution: BoolDistribution::MostlyFalse, |
| 161 | + }, |
| 162 | + BoolBenchArgs { |
| 163 | + total_length: 10_000, |
| 164 | + avg_run_length: 2, |
| 165 | + distribution: BoolDistribution::AllTrue, |
| 166 | + }, |
| 167 | + BoolBenchArgs { |
| 168 | + total_length: 10_000, |
| 169 | + avg_run_length: 10, |
| 170 | + distribution: BoolDistribution::AllTrue, |
| 171 | + }, |
| 172 | + BoolBenchArgs { |
| 173 | + total_length: 10_000, |
| 174 | + avg_run_length: 100, |
| 175 | + distribution: BoolDistribution::AllTrue, |
| 176 | + }, |
| 177 | + BoolBenchArgs { |
| 178 | + total_length: 10_000, |
| 179 | + avg_run_length: 1000, |
| 180 | + distribution: BoolDistribution::AllTrue, |
| 181 | + }, |
| 182 | + BoolBenchArgs { |
| 183 | + total_length: 10_000, |
| 184 | + avg_run_length: 2, |
| 185 | + distribution: BoolDistribution::AllFalse, |
| 186 | + }, |
| 187 | + BoolBenchArgs { |
| 188 | + total_length: 10_000, |
| 189 | + avg_run_length: 10, |
| 190 | + distribution: BoolDistribution::AllFalse, |
| 191 | + }, |
| 192 | + BoolBenchArgs { |
| 193 | + total_length: 10_000, |
| 194 | + avg_run_length: 100, |
| 195 | + distribution: BoolDistribution::AllFalse, |
| 196 | + }, |
| 197 | + BoolBenchArgs { |
| 198 | + total_length: 10_000, |
| 199 | + avg_run_length: 1000, |
| 200 | + distribution: BoolDistribution::AllFalse, |
| 201 | + }, |
75 | 202 | ]; |
76 | 203 |
|
77 | 204 | #[divan::bench(args = BOOL_ARGS)] |
78 | | -fn decode_bool_alternating(bencher: Bencher, (total_length, avg_run_length): (usize, usize)) { |
79 | | - let (ends, values) = |
80 | | - create_bool_test_data(total_length, avg_run_length, BoolDistribution::Alternating); |
81 | | - bencher.bench(|| runend_decode_bools(ends.clone(), values.clone(), 0, total_length)); |
82 | | -} |
83 | | - |
84 | | -#[divan::bench(args = BOOL_ARGS)] |
85 | | -fn decode_bool_mostly_true(bencher: Bencher, (total_length, avg_run_length): (usize, usize)) { |
86 | | - let (ends, values) = |
87 | | - create_bool_test_data(total_length, avg_run_length, BoolDistribution::MostlyTrue); |
88 | | - bencher.bench(|| runend_decode_bools(ends.clone(), values.clone(), 0, total_length)); |
89 | | -} |
90 | | - |
91 | | -#[divan::bench(args = BOOL_ARGS)] |
92 | | -fn decode_bool_mostly_false(bencher: Bencher, (total_length, avg_run_length): (usize, usize)) { |
93 | | - let (ends, values) = |
94 | | - create_bool_test_data(total_length, avg_run_length, BoolDistribution::MostlyFalse); |
95 | | - bencher.bench(|| runend_decode_bools(ends.clone(), values.clone(), 0, total_length)); |
96 | | -} |
97 | | - |
98 | | -#[divan::bench(args = BOOL_ARGS)] |
99 | | -fn decode_bool_all_true(bencher: Bencher, (total_length, avg_run_length): (usize, usize)) { |
100 | | - let (ends, values) = |
101 | | - create_bool_test_data(total_length, avg_run_length, BoolDistribution::AllTrue); |
102 | | - bencher.bench(|| runend_decode_bools(ends.clone(), values.clone(), 0, total_length)); |
103 | | -} |
104 | | - |
105 | | -#[divan::bench(args = BOOL_ARGS)] |
106 | | -fn decode_bool_all_false(bencher: Bencher, (total_length, avg_run_length): (usize, usize)) { |
107 | | - let (ends, values) = |
108 | | - create_bool_test_data(total_length, avg_run_length, BoolDistribution::AllFalse); |
109 | | - bencher.bench(|| runend_decode_bools(ends.clone(), values.clone(), 0, total_length)); |
| 205 | +fn decode_bool(bencher: Bencher, args: BoolBenchArgs) { |
| 206 | + let BoolBenchArgs { |
| 207 | + total_length, |
| 208 | + avg_run_length, |
| 209 | + distribution, |
| 210 | + } = args; |
| 211 | + let (bools, indices) = create_bool_test_data(total_length, avg_run_length, distribution); |
| 212 | + bencher |
| 213 | + .with_inputs(|| (&bools, &indices)) |
| 214 | + .bench_refs(|(ends, values)| { |
| 215 | + runend_decode_bools(ends.clone(), values.clone(), 0, total_length) |
| 216 | + }); |
110 | 217 | } |
0 commit comments