Skip to content

Commit

Permalink
add throughput benchmarks (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwwmanning authored Oct 10, 2024
1 parent 7b1df53 commit fd7897f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
38 changes: 36 additions & 2 deletions benches/bitpacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::mem::size_of;

use arrayref::{array_mut_ref, array_ref};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
use fastlanes::BitPacking;

fn pack(c: &mut Criterion) {
Expand Down Expand Up @@ -64,5 +64,39 @@ fn pack(c: &mut Criterion) {
}
}

criterion_group!(benches, pack);
fn throughput(c: &mut Criterion) {
const WIDTH: usize = 3;
const NUM_BATCHES: usize = 1024;
const N: usize = 1024 * NUM_BATCHES;
const OUTPUT_BATCH_SIZE: usize = 128 * WIDTH / size_of::<u16>();

let mut group = c.benchmark_group("throughput");
group.throughput(Throughput::Bytes(N as u64 * size_of::<u16>() as u64));
let mut values: Vec<u16> = (0..N).map(|i| (i % 8) as u16).collect();
let mut packed = vec![0u16; NUM_BATCHES * OUTPUT_BATCH_SIZE];

group.bench_function("compress", |b| {
b.iter(|| {
for i in 0..NUM_BATCHES {
BitPacking::pack::<WIDTH>(
array_ref![values, i * 1024, 1024],
array_mut_ref![packed, i * OUTPUT_BATCH_SIZE, OUTPUT_BATCH_SIZE],
);
}
});
});

group.bench_function("decompress", |b| {
b.iter(|| {
for i in 0..NUM_BATCHES {
BitPacking::unpack::<WIDTH>(
array_ref![packed, i * OUTPUT_BATCH_SIZE, OUTPUT_BATCH_SIZE],
array_mut_ref![values, i * 1024, 1024],
);
}
});
});
}

criterion_group!(benches, pack, throughput);
criterion_main!(benches);
40 changes: 38 additions & 2 deletions benches/delta.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use criterion::{criterion_group, criterion_main, Criterion};
use arrayref::{array_mut_ref, array_ref};
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use std::mem::size_of;

use fastlanes::{BitPacking, Delta, Transpose};
Expand All @@ -10,6 +11,7 @@ fn delta(c: &mut Criterion) {
const W: usize = 9;

let mut group = c.benchmark_group("delta");
group.throughput(Throughput::Bytes(1024 * size_of::<u16>() as u64));
let mut values: [u16; 1024] = [0; 1024];
for i in 0..1024 {
values[i] = (i / 8) as u16;
Expand Down Expand Up @@ -41,5 +43,39 @@ fn delta(c: &mut Criterion) {
});
}

criterion_group!(benches, delta);
fn throughput(c: &mut Criterion) {
const WIDTH: usize = 3;
const NUM_BATCHES: usize = 1024;
const N: usize = 1024 * NUM_BATCHES;
const OUTPUT_BATCH_SIZE: usize = 128 * WIDTH / size_of::<u16>();

let mut group = c.benchmark_group("throughput");
group.throughput(Throughput::Bytes(N as u64 * size_of::<u16>() as u64));
let mut values: Vec<u16> = (0..N).map(|i| (i % 8) as u16).collect();
let mut packed = vec![0u16; NUM_BATCHES * OUTPUT_BATCH_SIZE];

group.bench_function("compress", |b| {
b.iter(|| {
for i in 0..NUM_BATCHES {
BitPacking::pack::<WIDTH>(
array_ref![values, i * 1024, 1024],
array_mut_ref![packed, i * OUTPUT_BATCH_SIZE, OUTPUT_BATCH_SIZE],
);
}
});
});

group.bench_function("decompress", |b| {
b.iter(|| {
for i in 0..NUM_BATCHES {
BitPacking::unpack::<WIDTH>(
array_ref![packed, i * OUTPUT_BATCH_SIZE, OUTPUT_BATCH_SIZE],
array_mut_ref![values, i * 1024, 1024],
);
}
});
});
}

criterion_group!(benches, delta, throughput);
criterion_main!(benches);

0 comments on commit fd7897f

Please sign in to comment.