Skip to content

Commit

Permalink
Commit the rest of the benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnatsel committed Sep 29, 2024
1 parent fddcd46 commit 3a7a70d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ name = "unfilter"
harness = false
required-features = ["benchmarks"]

[[bench]]
path = "benches/filter.rs"
name = "filter"
harness = false
required-features = ["benchmarks"]

[[bench]]
path = "benches/expand_paletted.rs"
name = "expand_paletted"
Expand Down
5 changes: 3 additions & 2 deletions benches/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! ```
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use png::benchable_apis::filter;
use png::benchable_apis;
use png::FilterType;
use rand::Rng;

Expand Down Expand Up @@ -42,6 +42,7 @@ fn bench_filter(c: &mut Criterion, filter: FilterType, bpp: u8) {
let mut rng = rand::thread_rng();
let row_size = 4096 * (bpp as usize);
let two_rows = get_random_bytes(&mut rng, row_size * 2);
let mut out = vec![0; row_size];

group.throughput(Throughput::Bytes(row_size as u64));
group.bench_with_input(
Expand All @@ -50,7 +51,7 @@ fn bench_filter(c: &mut Criterion, filter: FilterType, bpp: u8) {
|b, two_rows| {
let (prev_row, curr_row) = two_rows.split_at(row_size);
let mut curr_row = curr_row.to_vec();
b.iter(|| filter(filter, bpp, prev_row, curr_row.as_mut_slice()));
b.iter(|| benchable_apis::filter(filter, bpp, prev_row, curr_row.as_mut_slice(), &mut out));
},
);
}
5 changes: 3 additions & 2 deletions src/benchable_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ pub fn unfilter(filter: FilterType, tbpp: u8, previous: &[u8], current: &mut [u8
crate::filter::unfilter(filter, tbpp, previous, current)
}

pub fn filter(filter: FilterType, tbpp: u8, previous: &[u8], current: &mut [u8]) {
pub fn filter(filter: FilterType, tbpp: u8, previous: &[u8], current: &[u8], output: &mut [u8]) {
let tbpp = BytesPerPixel::from_usize(tbpp as usize);
crate::filter::filter(filter, tbpp, previous, current)
let adaptive = crate::AdaptiveFilterType::NonAdaptive;
crate::filter::filter(filter, adaptive, tbpp, previous, current, output);
}

pub use crate::decoder::transform::{create_transform_fn, TransformFn};
Expand Down

0 comments on commit 3a7a70d

Please sign in to comment.