aboutsummaryrefslogtreecommitdiff
path: root/vendor/weezl/benches
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/weezl/benches
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/weezl/benches')
-rw-r--r--vendor/weezl/benches/msb8.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/weezl/benches/msb8.rs b/vendor/weezl/benches/msb8.rs
new file mode 100644
index 0000000..a7e5dc5
--- /dev/null
+++ b/vendor/weezl/benches/msb8.rs
@@ -0,0 +1,54 @@
+extern crate criterion;
+extern crate weezl;
+
+use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+use std::fs;
+use weezl::{decode::Decoder, BitOrder, LzwStatus};
+
+pub fn criterion_benchmark(c: &mut Criterion, file: &str) {
+ let data = fs::read(file).expect("Benchmark input not found");
+ let mut group = c.benchmark_group("msb-8");
+ let id = BenchmarkId::new(file, data.len());
+ let mut outbuf = vec![0; 1 << 26]; // 64MB, what wuff uses..
+ let mut decode_once = |data: &[u8]| {
+ let mut decoder = Decoder::new(BitOrder::Msb, 8);
+ let mut written = 0;
+ let outbuf = outbuf.as_mut_slice();
+ let mut data = data;
+ loop {
+ let result = decoder.decode_bytes(data, &mut outbuf[..]);
+ let done = result.status.expect("Error");
+ data = &data[result.consumed_in..];
+ written += result.consumed_out;
+ black_box(&outbuf[..result.consumed_out]);
+ if let LzwStatus::Done = done {
+ break;
+ }
+ if let LzwStatus::NoProgress = done {
+ panic!("Need to make progress");
+ }
+ }
+ written
+ };
+ group.throughput(Throughput::Bytes(decode_once(&data) as u64));
+ group.bench_with_input(id, &data, |b, data| {
+ b.iter(|| {
+ decode_once(data);
+ })
+ });
+}
+
+pub fn bench_toml(c: &mut Criterion) {
+ criterion_benchmark(c, "benches/Cargo-8-msb.lzw");
+}
+
+pub fn bench_binary(c: &mut Criterion) {
+ criterion_benchmark(c, "benches/binary-8-msb.lzw");
+}
+
+pub fn bench_lib(c: &mut Criterion) {
+ criterion_benchmark(c, "benches/lib-8-msb.lzw");
+}
+
+criterion_group!(benches, bench_toml, bench_binary, bench_lib);
+criterion_main!(benches);