From 16c5d82640ad25eefab4439bbbd97aad4ae8ee37 Mon Sep 17 00:00:00 2001 From: Lukasz Anforowicz Date: Tue, 26 Sep 2023 23:58:35 +0000 Subject: [PATCH] git squash commit for iai-benchmarks. 54671350698ec53bb67cb827bf86f96fcc2ba49f . 7cfc1838cc3316f0b0ce0e567adf9df83d7cea59 . --- Cargo.toml | 7 +++++++ benches/decoder.rs | 2 +- benches/decoder_iai.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 benches/decoder_iai.rs 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, +}