Skip to content

Commit

Permalink
Add small benchmark sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
alajpie committed Jun 16, 2020
1 parent fd367f8 commit fa76832
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions benches/encdec.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use urbit_q::*;

fn enc(c: &mut Criterion) {
fn enc1k(c: &mut Criterion) {
let bytes: Vec<u8> = (0..1024).map(|_| rand::random()).collect();
c.bench_function("encode 1k", |b| {
b.iter(|| encode(black_box(&bytes)))
});
c.bench_function("encode 1k", |b| b.iter(|| encode(black_box(&bytes))));
}

fn dec(c: &mut Criterion) {
fn enc8(c: &mut Criterion) {
let bytes: Vec<u8> = (0..8).map(|_| rand::random()).collect();
c.bench_function("encode 8", |b| b.iter(|| encode(black_box(&bytes))));
}

fn dec1k(c: &mut Criterion) {
let bytes: Vec<u8> = (0..1024).map(|_| rand::random()).collect();
let string = encode(&bytes);
c.bench_function("decode 1k", |b| {
b.iter(|| decode(black_box(&string)))
});
c.bench_function("decode 1k", |b| b.iter(|| decode(black_box(&string))));
}

fn dec8(c: &mut Criterion) {
let bytes: Vec<u8> = (0..8).map(|_| rand::random()).collect();
let string = encode(&bytes);
c.bench_function("decode 8", |b| b.iter(|| decode(black_box(&string))));
}

criterion_group!(benches, enc, dec);
criterion_group!(benches, enc1k, enc8, dec1k, dec8);
criterion_main!(benches);

0 comments on commit fa76832

Please sign in to comment.