diff --git a/Cargo.toml b/Cargo.toml index fcc45e18..3b3a7de7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ criterion = "0.3.1" getopts = "0.2.14" glium = { version = "0.32", features = ["glutin"], default-features = false } glob = "0.3" +iai = "0.1" rand = "0.8.4" term = "0.7" @@ -50,3 +51,9 @@ path = "benches/unfilter.rs" name = "unfilter" harness = false required-features = ["benchmarks"] + +[[bench]] +path = "benches/decoder_iai.rs" +name = "decoder_iai" +harness = false + diff --git a/benches/decoder.rs b/benches/decoder.rs index a078c9a0..5acd7964 100644 --- a/benches/decoder.rs +++ b/benches/decoder.rs @@ -20,7 +20,7 @@ criterion_main!(benches); fn bench_file(c: &mut Criterion, data: Vec, name: String) { let mut group = c.benchmark_group("decode"); - group.sample_size(20); + //group.sample_size(20); let decoder = Decoder::new(&*data); let mut reader = decoder.read_info().unwrap(); diff --git a/benches/decoder_iai.rs b/benches/decoder_iai.rs new file mode 100644 index 00000000..8b954b8a --- /dev/null +++ b/benches/decoder_iai.rs @@ -0,0 +1,33 @@ +use iai::black_box; + +fn decode(data: &[u8]) -> Vec { + let data = black_box(data); + let decoder = png::Decoder::new(data); + let mut reader = decoder.read_info().unwrap(); + let mut image = vec![0; reader.output_buffer_size()]; + reader.next_frame(&mut image).unwrap(); + image +} + +fn iai_decode_kodim02() -> Vec { + decode(include_bytes!("../tests/benches/kodim02.png")) +} + +fn iai_decode_kodim07() -> Vec { + decode(include_bytes!("../tests/benches/kodim07.png")) +} + +fn iai_decode_kodim17() -> Vec { + decode(include_bytes!("../tests/benches/kodim17.png")) +} + +fn iai_decode_kodim23() -> Vec { + decode(include_bytes!("../tests/benches/kodim23.png")) +} + +iai::main!{ + iai_decode_kodim02, + iai_decode_kodim07, + iai_decode_kodim17, + iai_decode_kodim23, +}