|
| 1 | +#![allow(clippy::cast_possible_truncation, clippy::use_debug)] |
| 2 | + |
| 3 | +use vortex_buffer::{Buffer, BufferMut}; |
| 4 | + |
| 5 | +fn generate_dataset(max_run: u32, distinct: u32) -> Buffer<u32> { |
| 6 | + let mut output = BufferMut::with_capacity(64_000); |
| 7 | + let mut run = 0; |
| 8 | + let mut value = 0; |
| 9 | + for _ in 0..64_000 { |
| 10 | + if run == 0 { |
| 11 | + value = rand::random::<u32>() % distinct; |
| 12 | + run = std::cmp::max(rand::random::<u32>() % max_run, 1); |
| 13 | + } |
| 14 | + output.push(value); |
| 15 | + run -= 1; |
| 16 | + } |
| 17 | + |
| 18 | + output.freeze() |
| 19 | +} |
| 20 | + |
| 21 | +#[derive(Debug, Copy, Clone)] |
| 22 | +enum Distribution { |
| 23 | + LowCardinality, |
| 24 | + ShortRuns, |
| 25 | + LongRuns, |
| 26 | +} |
| 27 | + |
| 28 | +#[divan::bench_group(items_count = 64_000u32, bytes_count = 256_000u32)] |
| 29 | +mod stats { |
| 30 | + use divan::Bencher; |
| 31 | + use vortex_array::array::PrimitiveArray; |
| 32 | + use vortex_array::validity::Validity; |
| 33 | + use vortex_btrblocks::integer::IntegerStats; |
| 34 | + use vortex_btrblocks::{CompressorStats, GenerateStatsOptions}; |
| 35 | + use vortex_buffer::Buffer; |
| 36 | + |
| 37 | + use crate::{generate_dataset, Distribution}; |
| 38 | + |
| 39 | + fn generate_low_cardinality() -> PrimitiveArray { |
| 40 | + let values: Buffer<u32> = (0..1024).cycle().take(64_000).collect(); |
| 41 | + PrimitiveArray::new(values, Validity::NonNullable) |
| 42 | + } |
| 43 | + |
| 44 | + fn generate_runs(max_run: u32) -> PrimitiveArray { |
| 45 | + let values = generate_dataset(max_run, 1024); |
| 46 | + PrimitiveArray::new(values, Validity::NonNullable) |
| 47 | + } |
| 48 | + |
| 49 | + #[divan::bench(args = [Distribution::LowCardinality, Distribution::ShortRuns, Distribution::LongRuns])] |
| 50 | + fn stats_dict_on(bencher: Bencher, distribution: Distribution) { |
| 51 | + let values = match distribution { |
| 52 | + Distribution::LowCardinality => generate_low_cardinality(), |
| 53 | + Distribution::ShortRuns => generate_runs(4), |
| 54 | + Distribution::LongRuns => generate_runs(64), |
| 55 | + }; |
| 56 | + |
| 57 | + bencher.with_inputs(|| values.clone()).bench_refs(|values| { |
| 58 | + IntegerStats::generate_opts(values, GenerateStatsOptions::default()); |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + #[divan::bench(args = [Distribution::LowCardinality, Distribution::ShortRuns, Distribution::LongRuns])] |
| 63 | + fn stats_dict_off(bencher: Bencher, distribution: Distribution) { |
| 64 | + let values = match distribution { |
| 65 | + Distribution::LowCardinality => generate_low_cardinality(), |
| 66 | + Distribution::ShortRuns => generate_runs(4), |
| 67 | + Distribution::LongRuns => generate_runs(64), |
| 68 | + }; |
| 69 | + |
| 70 | + bencher.with_inputs(|| values.clone()).bench_refs(|values| { |
| 71 | + IntegerStats::generate_opts( |
| 72 | + values, |
| 73 | + GenerateStatsOptions { |
| 74 | + count_distinct_values: false, |
| 75 | + }, |
| 76 | + ); |
| 77 | + }); |
| 78 | + } |
| 79 | +} |
| 80 | +fn main() { |
| 81 | + divan::main(); |
| 82 | +} |
0 commit comments