|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 |
2 | 2 | // SPDX-FileCopyrightText: Copyright the Vortex contributors |
3 | 3 |
|
| 4 | +//! Benchmarks for the binary comparison path, over every array kind it accepts. |
| 5 | +//! |
| 6 | +//! `compare_int_constant_left`, `compare_u8`, `compare_u64`, and `compare_f32` carry |
| 7 | +//! `#[cpu_features]`, so they are measured on every walltime CPU-feature leg rather than in |
| 8 | +//! simulation. Each is written once and compiled differently per leg: today the primitive |
| 9 | +//! comparison path is a portable lane kernel, and how well it auto-vectorizes is decided by |
| 10 | +//! the build. That is the baseline a hand-written kernel selected through |
| 11 | +//! `cfg(target_feature)` has to beat, measured on the silicon it would run on. |
| 12 | +
|
4 | 13 | #![expect(clippy::unwrap_used)] |
5 | 14 |
|
6 | 15 | use divan::Bencher; |
| 16 | +use divan::counter::ItemsCount; |
7 | 17 | use mimalloc::MiMalloc; |
8 | 18 | use rand::RngExt; |
9 | 19 | use rand::SeedableRng; |
@@ -38,7 +48,10 @@ const ARRAY_SIZE: usize = 8_192; |
38 | 48 |
|
39 | 49 | fn bench_compare(bencher: Bencher, lhs: ArrayRef, rhs: ArrayRef, op: Operator) { |
40 | 50 | let session = vortex_array::array_session(); |
| 51 | + let len = lhs.len(); |
| 52 | + |
41 | 53 | bencher |
| 54 | + .counter(ItemsCount::new(len)) |
42 | 55 | .with_inputs(|| (&lhs, &rhs, session.create_execution_ctx())) |
43 | 56 | .bench_refs(|input| { |
44 | 57 | input |
@@ -88,6 +101,27 @@ fn float_array(rng: &mut StdRng) -> ArrayRef { |
88 | 101 | .into_array() |
89 | 102 | } |
90 | 103 |
|
| 104 | +fn u8_array(rng: &mut StdRng) -> ArrayRef { |
| 105 | + (0..ARRAY_SIZE) |
| 106 | + .map(|_| rng.random::<u8>()) |
| 107 | + .collect::<Buffer<_>>() |
| 108 | + .into_array() |
| 109 | +} |
| 110 | + |
| 111 | +fn u64_array(rng: &mut StdRng) -> ArrayRef { |
| 112 | + (0..ARRAY_SIZE) |
| 113 | + .map(|_| rng.random::<u64>()) |
| 114 | + .collect::<Buffer<_>>() |
| 115 | + .into_array() |
| 116 | +} |
| 117 | + |
| 118 | +fn f32_array(rng: &mut StdRng) -> ArrayRef { |
| 119 | + (0..ARRAY_SIZE) |
| 120 | + .map(|_| rng.random_range(0.0f32..1.0)) |
| 121 | + .collect::<Buffer<_>>() |
| 122 | + .into_array() |
| 123 | +} |
| 124 | + |
91 | 125 | fn string_array(rng: &mut StdRng) -> ArrayRef { |
92 | 126 | VarBinViewArray::from_iter_str((0..ARRAY_SIZE).map(|_| { |
93 | 127 | let len = rng.random_range(1usize..24); |
@@ -154,6 +188,42 @@ fn compare_int_constant(bencher: Bencher) { |
154 | 188 | bench_compare(bencher, arr, constant, Operator::Gte); |
155 | 189 | } |
156 | 190 |
|
| 191 | +#[vortex_bench_support::cpu_features] |
| 192 | +#[divan::bench] |
| 193 | +fn compare_int_constant_left(bencher: Bencher) { |
| 194 | + let mut rng = StdRng::seed_from_u64(0); |
| 195 | + let constant = ConstantArray::new(50_000_000i64, ARRAY_SIZE).into_array(); |
| 196 | + let arr = int_array(&mut rng); |
| 197 | + bench_compare(bencher, constant, arr, Operator::Lte); |
| 198 | +} |
| 199 | + |
| 200 | +#[vortex_bench_support::cpu_features] |
| 201 | +#[divan::bench] |
| 202 | +fn compare_u8(bencher: Bencher) { |
| 203 | + let mut rng = StdRng::seed_from_u64(0); |
| 204 | + let arr1 = u8_array(&mut rng); |
| 205 | + let arr2 = u8_array(&mut rng); |
| 206 | + bench_compare(bencher, arr1, arr2, Operator::Gte); |
| 207 | +} |
| 208 | + |
| 209 | +#[vortex_bench_support::cpu_features] |
| 210 | +#[divan::bench] |
| 211 | +fn compare_u64(bencher: Bencher) { |
| 212 | + let mut rng = StdRng::seed_from_u64(0); |
| 213 | + let arr1 = u64_array(&mut rng); |
| 214 | + let arr2 = u64_array(&mut rng); |
| 215 | + bench_compare(bencher, arr1, arr2, Operator::Gte); |
| 216 | +} |
| 217 | + |
| 218 | +#[vortex_bench_support::cpu_features] |
| 219 | +#[divan::bench] |
| 220 | +fn compare_f32(bencher: Bencher) { |
| 221 | + let mut rng = StdRng::seed_from_u64(0); |
| 222 | + let arr1 = f32_array(&mut rng); |
| 223 | + let arr2 = f32_array(&mut rng); |
| 224 | + bench_compare(bencher, arr1, arr2, Operator::Gte); |
| 225 | +} |
| 226 | + |
157 | 227 | #[divan::bench] |
158 | 228 | fn compare_int_eq(bencher: Bencher) { |
159 | 229 | let mut rng = StdRng::seed_from_u64(0); |
|
0 commit comments