test: add integer encoder/decoder benchmarks

pull/24376/head
Edd Robinson 2020-01-21 15:01:53 +00:00
parent 4185307d78
commit bd8246d561
4 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,30 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use rand::Rng;
fn integer_decode_random(c: &mut Criterion) {
let mut group = c.benchmark_group("integer_decode_random");
for batch_size in [
10_i32, 25, 50, 100, 250, 500, 750, 1000, 5000, 10000, 50000, 100000,
]
.iter()
{
let src: Vec<i64> = (1..*batch_size)
.map(|_| rand::thread_rng().gen_range(0, 100))
.collect();
let mut dst = vec![];
delorean::encoders::integer::encode_all(&src, &mut dst).unwrap();
group.throughput(Throughput::Bytes(dst.len() as u64));
group.bench_with_input(BenchmarkId::from_parameter(batch_size), &src, |b, src| {
let mut src_mut = src.clone();
b.iter(|| {
src_mut.truncate(0);
delorean::encoders::integer::decode_all(&dst, &mut src_mut).unwrap();
});
});
}
group.finish();
}
criterion_group!(benches, integer_decode_random);
criterion_main!(benches);

View File

@ -0,0 +1,27 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
fn integer_decode_sequential(c: &mut Criterion) {
let mut group = c.benchmark_group("integer_decode_sequential");
for batch_size in [
10_i32, 25, 50, 100, 250, 500, 750, 1000, 5000, 10000, 50000, 100000,
]
.iter()
{
let src: Vec<i64> = (1..*batch_size).map(i64::from).collect();
let mut dst = vec![];
delorean::encoders::integer::encode_all(&src, &mut dst).unwrap();
group.throughput(Throughput::Bytes(dst.len() as u64));
group.bench_with_input(BenchmarkId::from_parameter(batch_size), &src, |b, src| {
let mut src_mut = src.clone();
b.iter(|| {
src_mut.truncate(0);
delorean::encoders::integer::decode_all(&dst, &mut src_mut).unwrap();
});
});
}
group.finish();
}
criterion_group!(benches, integer_decode_sequential);
criterion_main!(benches);

View File

@ -0,0 +1,47 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use rand::Rng;
// The current integer encoder produces the following compression:
//
// values block size compression
// 10 25 20.00 bits/value
// 25 33 10.56 bits/value
// 50 65 10.40 bits/value
// 100 121 9.68 bits/value
// 250 281 8.99 bits/value
// 500 561 8.97 bits/value
// 750 833 8.88 bits/value
// 1000 1105 8.84 bits/value
// 5000 5425 8.68 bits/value
// 10000 10865 8.69 bits/value
// 50000 54361 8.69 bits/value
// 100000 108569 8.68 bits/value
//
fn integer_encode_random(c: &mut Criterion) {
let mut group = c.benchmark_group("integer_encode_random");
for batch_size in [
10_i32, 25, 50, 100, 250, 500, 750, 1000, 5000, 10000, 50000, 100000,
]
.iter()
{
group.throughput(Throughput::Bytes(*batch_size as u64 * 8));
group.bench_with_input(
BenchmarkId::from_parameter(batch_size),
batch_size,
|b, &batch_size| {
let src: Vec<i64> = (1..batch_size)
.map(|_| rand::thread_rng().gen_range(0, 100))
.collect();
let mut dst = vec![];
b.iter(|| {
dst.truncate(0);
delorean::encoders::integer::encode_all(&src, &mut dst).unwrap();
});
},
);
}
group.finish();
}
criterion_group!(benches, integer_encode_random);
criterion_main!(benches);

View File

@ -0,0 +1,46 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
// The current integer encoder produces the following compression. Note, since
// a sequential range of values can be encoded using RLE the compression
// statistics are not very interesting.
//
// values block size compression
// 10 11 8.80 bits/value
// 25 11 3.52 bits/value
// 50 11 1.76 bits/value
// 100 11 0.88 bits/value
// 250 12 0.38 bits/value
// 500 12 0.19 bits/value
// 750 12 0.12 bits/value
// 1000 12 0.09 bits/value
// 5000 12 0.01 bits/value
// 10000 12 0.00 bits/value
// 50000 13 0.00 bits/value
// 100000 13 0.00 bits/value
//
fn integer_encode_sequential(c: &mut Criterion) {
let mut group = c.benchmark_group("integer_encode_sequential");
for batch_size in [
10_i32, 25, 50, 100, 250, 500, 750, 1000, 5000, 10000, 50000, 100000,
]
.iter()
{
group.throughput(Throughput::Bytes(*batch_size as u64 * 8));
group.bench_with_input(
BenchmarkId::from_parameter(batch_size),
batch_size,
|b, &batch_size| {
let src: Vec<i64> = (1..batch_size).map(i64::from).collect();
let mut dst = vec![];
b.iter(|| {
dst.truncate(0);
delorean::encoders::integer::encode_all(&src, &mut dst).unwrap();
});
},
);
}
group.finish();
}
criterion_group!(benches, integer_encode_sequential);
criterion_main!(benches);