PR https://github.com/shssoichiro/oxipng/pull/445 did some dependency updates, which included using the latest zopfli version. The latest version of this crate exposes new options in its API that allow users to choose the desired number of Zopfli compression iterations, which may greatly affect execution time. In fact, other optimizers such as zopflipng dynamically select this number depending on the input file size (see: https://github.com/shssoichiro/oxipng/issues/414). As a first step towards making OxiPNG deal with Zopfli better, let's add the necessary options for libraries to be able to choose the number of iterations. This number is still fixed to 15 as before when using the CLI.
68 lines
1.9 KiB
Rust
68 lines
1.9 KiB
Rust
#![feature(test)]
|
|
|
|
extern crate oxipng;
|
|
extern crate test;
|
|
|
|
use oxipng::internal_tests::*;
|
|
use std::num::NonZeroU8;
|
|
use std::path::PathBuf;
|
|
use test::Bencher;
|
|
|
|
// SAFETY: trivially safe. Stopgap solution until const unwrap is stabilized.
|
|
const DEFAULT_ZOPFLI_ITERATIONS: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(15) };
|
|
|
|
#[bench]
|
|
fn zopfli_16_bits_strategy_0(b: &mut Bencher) {
|
|
let input = test::black_box(PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"));
|
|
let png = PngData::new(&input, false).unwrap();
|
|
|
|
b.iter(|| {
|
|
zopfli_deflate(png.raw.data.as_ref(), DEFAULT_ZOPFLI_ITERATIONS).ok();
|
|
});
|
|
}
|
|
|
|
#[bench]
|
|
fn zopfli_8_bits_strategy_0(b: &mut Bencher) {
|
|
let input = test::black_box(PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"));
|
|
let png = PngData::new(&input, false).unwrap();
|
|
|
|
b.iter(|| {
|
|
zopfli_deflate(png.raw.data.as_ref(), DEFAULT_ZOPFLI_ITERATIONS).ok();
|
|
});
|
|
}
|
|
|
|
#[bench]
|
|
fn zopfli_4_bits_strategy_0(b: &mut Bencher) {
|
|
let input = test::black_box(PathBuf::from(
|
|
"tests/files/palette_4_should_be_palette_4.png",
|
|
));
|
|
let png = PngData::new(&input, false).unwrap();
|
|
|
|
b.iter(|| {
|
|
zopfli_deflate(png.raw.data.as_ref(), DEFAULT_ZOPFLI_ITERATIONS).ok();
|
|
});
|
|
}
|
|
|
|
#[bench]
|
|
fn zopfli_2_bits_strategy_0(b: &mut Bencher) {
|
|
let input = test::black_box(PathBuf::from(
|
|
"tests/files/palette_2_should_be_palette_2.png",
|
|
));
|
|
let png = PngData::new(&input, false).unwrap();
|
|
|
|
b.iter(|| {
|
|
zopfli_deflate(png.raw.data.as_ref(), DEFAULT_ZOPFLI_ITERATIONS).ok();
|
|
});
|
|
}
|
|
|
|
#[bench]
|
|
fn zopfli_1_bits_strategy_0(b: &mut Bencher) {
|
|
let input = test::black_box(PathBuf::from(
|
|
"tests/files/palette_1_should_be_palette_1.png",
|
|
));
|
|
let png = PngData::new(&input, false).unwrap();
|
|
|
|
b.iter(|| {
|
|
zopfli_deflate(png.raw.data.as_ref(), DEFAULT_ZOPFLI_ITERATIONS).ok();
|
|
});
|
|
}
|