Skip to content

Commit

Permalink
Fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
aswaving committed Apr 16, 2019
1 parent 5796612 commit 5f958a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
33 changes: 13 additions & 20 deletions benches/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@
extern crate criterion;

extern crate yenc;

use std::env::temp_dir;
use std::io::Cursor;

use criterion::Criterion;
use criterion::*;

fn decode(c: &mut Criterion) {
// write random data in file
let buf = (0..32_768).map(|c| (c % 256) as u8).collect::<Vec<u8>>();
let length = buf.len() as u64;

let mut out = Vec::<u8>::with_capacity(32768 * 102 / 100);
let encode_options = yenc::EncodeOptions::default().begin(1).end(length);
let cur = Cursor::new(buf);
encode_options.encode_stream(cur, &mut out, length, "test").unwrap();
let mut buf = (0..32_768).map(|c| (c % 256) as u8).collect::<Vec<u8>>();
let length = buf.len();
let mut encoded = Vec::with_capacity(32_768 * 102 / 100);
yenc::encode_buffer(&buf, 0, 128, &mut encoded).unwrap();

c.bench_function("decode 32k", move |b| {
let mut cur = Cursor::new(out.clone());
let output_dir = temp_dir();
let output_dir = output_dir.to_str().unwrap();
let decode_options = yenc::DecodeOptions::new(output_dir);
b.iter(|| decode_options.decode_stream(&mut cur).unwrap())
});
c.bench(
"decode",
Benchmark::new("decode 32k", move |b| {
buf.clear();
b.iter(|| yenc::decode_buffer(&encoded).unwrap())
})
.throughput(Throughput::Bytes(length as u32)),
);
}

criterion_group!(benches, decode);
Expand Down
18 changes: 12 additions & 6 deletions benches/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
extern crate criterion;
extern crate yenc;

use criterion::Criterion;
use criterion::*;

fn encode_buffer(c: &mut Criterion) {
let buf = (0..32_768).map(|c| (c % 256) as u8).collect::<Vec<u8>>();
c.bench_function("encode 32k", move |b| {
b.iter(|| {
let mut output = Vec::with_capacity(32_768 * 102 / 100);
yenc::encode_buffer(&buf, 0, 128, &mut output).unwrap()
let length = buf.len();
let mut output = Vec::with_capacity(32_768 * 102 / 100);
c.bench(
"encode",
Benchmark::new("encode 32k", move |b| {
b.iter(|| {
output.clear();
yenc::encode_buffer(&buf, 0, 128, &mut output).unwrap()
})
})
});
.throughput(Throughput::Bytes(length as u32)),
);
}

criterion_group!(benches, encode_buffer);
Expand Down

0 comments on commit 5f958a3

Please sign in to comment.