use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use rand::Rng;
use std::convert::TryFrom;
use std::mem;
use packers::Packer;
const BATCH_SIZES: [usize; 6] = [10, 100, 1000, 10_000, 100_000, 1_000_000];
fn packer_insert_non_null(c: &mut Criterion) {
benchmark_push(c, "packer_insert_non_null", &BATCH_SIZES);
}
fn packer_insert_with_null(c: &mut Criterion) {
benchmark_push_option(c, "packer_insert_with_null", &BATCH_SIZES);
}
fn packer_get_element(c: &mut Criterion) {
benchmark_get(c, "packer_get_element", &BATCH_SIZES);
}
fn packer_iter(c: &mut Criterion) {
benchmark_iter(c, "packer_iter", &BATCH_SIZES[..4]);
}
fn benchmark_push(c: &mut Criterion, benchmark_group_name: &str, batch_sizes: &[usize]) {
let mut group = c.benchmark_group(benchmark_group_name);
for &batch_size in batch_sizes {
let input = vec![0_u64; batch_size];
group.throughput(Throughput::Bytes(u64::try_from(input.len() * 8).unwrap()));
group.bench_with_input(
BenchmarkId::from_parameter(batch_size),
&input,
|b, input| {
b.iter(|| {
let mut packer = Packer::with_capacity(input.len());
for v in input {
packer.push(*v);
}
});
},
);
}
group.finish();
}
fn i64_vec_with_nulls(size: usize, null_percent: usize) -> Vec