Test: update benchmark dependencies

This commit is contained in:
Lovell Fuller 2023-01-24 15:21:31 +00:00
parent a532659b0f
commit 802f560b9b
2 changed files with 73 additions and 19 deletions

View File

@ -8,7 +8,7 @@
"test": "node perf && node random && node parallel" "test": "node perf && node random && node parallel"
}, },
"dependencies": { "dependencies": {
"@squoosh/cli": "0.7.2", "@squoosh/cli": "0.7.3",
"@squoosh/lib": "0.4.0", "@squoosh/lib": "0.4.0",
"async": "3.2.4", "async": "3.2.4",
"benchmark": "2.1.4", "benchmark": "2.1.4",
@ -18,7 +18,7 @@
"semver": "7.3.8" "semver": "7.3.8"
}, },
"optionalDependencies": { "optionalDependencies": {
"@tensorflow/tfjs-node": "4.1.0", "@tensorflow/tfjs-node": "4.2.0",
"mapnik": "4.5.9" "mapnik": "4.5.9"
}, },
"license": "Apache-2.0", "license": "Apache-2.0",

View File

@ -32,6 +32,7 @@ const outputWebP = fixtures.path('output.webp');
const width = 720; const width = 720;
const height = 588; const height = 588;
const heightPng = 540;
// Disable libvips cache to ensure tests are as fair as they can be // Disable libvips cache to ensure tests are as fair as they can be
sharp.cache(false); sharp.cache(false);
@ -648,7 +649,7 @@ async.series({
throw err; throw err;
} else { } else {
image image
.resize(width, height) .resize(width, heightPng)
.deflateLevel(6) .deflateLevel(6)
.filterType(0) .filterType(0)
.getBuffer(jimp.MIME_PNG, function (err) { .getBuffer(jimp.MIME_PNG, function (err) {
@ -669,7 +670,7 @@ async.series({
throw err; throw err;
} else { } else {
image image
.resize(width, height) .resize(width, heightPng)
.deflateLevel(6) .deflateLevel(6)
.filterType(0) .filterType(0)
.write(outputPng, function (err) { .write(outputPng, function (err) {
@ -683,6 +684,59 @@ async.series({
}); });
} }
}); });
// squoosh-cli
pngSuite.add('squoosh-cli-file-file', {
defer: true,
fn: function (deferred) {
exec(`./node_modules/.bin/squoosh-cli \
--output-dir ${os.tmpdir()} \
--resize '{"enabled":true,"width":${width},"height":${heightPng},"method":"lanczos3","premultiply":true,"linearRGB":false}' \
--oxipng '{"level":1}' \
"${fixtures.inputPngAlphaPremultiplicationLarge}"`, function (err) {
if (err) {
throw err;
}
deferred.resolve();
});
}
});
// squoosh-lib (GPLv3)
pngSuite.add('squoosh-lib-buffer-buffer', {
defer: true,
fn: function (deferred) {
const pool = new squoosh.ImagePool();
const image = pool.ingestImage(inputPngBuffer);
image.decoded
.then(function () {
return image.preprocess({
resize: {
enabled: true,
width,
height: heightPng,
method: 'lanczos3',
premultiply: true,
linearRGB: false
}
});
})
.then(function () {
return image.encode({
oxipng: {
level: 1
}
});
})
.then(function () {
return pool.close();
})
.then(function () {
return image.encodedWith.oxipng;
})
.then(function () {
deferred.resolve();
});
}
});
// mapnik // mapnik
mapnik && pngSuite.add('mapnik-file-file', { mapnik && pngSuite.add('mapnik-file-file', {
defer: true, defer: true,
@ -691,13 +745,13 @@ async.series({
if (err) throw err; if (err) throw err;
img.premultiply(function (err, img) { img.premultiply(function (err, img) {
if (err) throw err; if (err) throw err;
img.resize(width, height, { img.resize(width, heightPng, {
scaling_method: mapnik.imageScaling.lanczos scaling_method: mapnik.imageScaling.lanczos
}, function (err, img) { }, function (err, img) {
if (err) throw err; if (err) throw err;
img.demultiply(function (err, img) { img.demultiply(function (err, img) {
if (err) throw err; if (err) throw err;
img.save(outputPng, 'png', function (err) { img.save(outputPng, 'png32:f=no:z=6', function (err) {
if (err) throw err; if (err) throw err;
deferred.resolve(); deferred.resolve();
}); });
@ -713,13 +767,13 @@ async.series({
if (err) throw err; if (err) throw err;
img.premultiply(function (err, img) { img.premultiply(function (err, img) {
if (err) throw err; if (err) throw err;
img.resize(width, height, { img.resize(width, heightPng, {
scaling_method: mapnik.imageScaling.lanczos scaling_method: mapnik.imageScaling.lanczos
}, function (err, img) { }, function (err, img) {
if (err) throw err; if (err) throw err;
img.demultiply(function (err, img) { img.demultiply(function (err, img) {
if (err) throw err; if (err) throw err;
img.encode('png', function (err) { img.encode('png32:f=no:z=6', function (err) {
if (err) throw err; if (err) throw err;
deferred.resolve(); deferred.resolve();
}); });
@ -737,7 +791,7 @@ async.series({
srcPath: fixtures.inputPngAlphaPremultiplicationLarge, srcPath: fixtures.inputPngAlphaPremultiplicationLarge,
dstPath: outputPng, dstPath: outputPng,
width: width, width: width,
height: height, height: heightPng,
filter: 'Lanczos', filter: 'Lanczos',
customArgs: [ customArgs: [
'-define', 'PNG:compression-level=6', '-define', 'PNG:compression-level=6',
@ -758,7 +812,7 @@ async.series({
fn: function (deferred) { fn: function (deferred) {
gm(fixtures.inputPngAlphaPremultiplicationLarge) gm(fixtures.inputPngAlphaPremultiplicationLarge)
.filter('Lanczos') .filter('Lanczos')
.resize(width, height) .resize(width, heightPng)
.define('PNG:compression-level=6') .define('PNG:compression-level=6')
.define('PNG:compression-filter=0') .define('PNG:compression-filter=0')
.write(outputPng, function (err) { .write(outputPng, function (err) {
@ -774,7 +828,7 @@ async.series({
fn: function (deferred) { fn: function (deferred) {
gm(fixtures.inputPngAlphaPremultiplicationLarge) gm(fixtures.inputPngAlphaPremultiplicationLarge)
.filter('Lanczos') .filter('Lanczos')
.resize(width, height) .resize(width, heightPng)
.define('PNG:compression-level=6') .define('PNG:compression-level=6')
.define('PNG:compression-filter=0') .define('PNG:compression-filter=0')
.toBuffer(function (err) { .toBuffer(function (err) {
@ -792,7 +846,7 @@ async.series({
minSamples, minSamples,
fn: function (deferred) { fn: function (deferred) {
sharp(inputPngBuffer) sharp(inputPngBuffer)
.resize(width, height) .resize(width, heightPng)
.png({ compressionLevel: 6 }) .png({ compressionLevel: 6 })
.toFile(outputPng, function (err) { .toFile(outputPng, function (err) {
if (err) { if (err) {
@ -807,9 +861,9 @@ async.series({
minSamples, minSamples,
fn: function (deferred) { fn: function (deferred) {
sharp(inputPngBuffer) sharp(inputPngBuffer)
.resize(width, height) .resize(width, heightPng)
.png({ compressionLevel: 6 }) .png({ compressionLevel: 6 })
.toBuffer(function (err) { .toBuffer(function (err, data) {
if (err) { if (err) {
throw err; throw err;
} else { } else {
@ -822,7 +876,7 @@ async.series({
minSamples, minSamples,
fn: function (deferred) { fn: function (deferred) {
sharp(fixtures.inputPngAlphaPremultiplicationLarge) sharp(fixtures.inputPngAlphaPremultiplicationLarge)
.resize(width, height) .resize(width, heightPng)
.png({ compressionLevel: 6 }) .png({ compressionLevel: 6 })
.toFile(outputPng, function (err) { .toFile(outputPng, function (err) {
if (err) { if (err) {
@ -837,7 +891,7 @@ async.series({
minSamples, minSamples,
fn: function (deferred) { fn: function (deferred) {
sharp(fixtures.inputPngAlphaPremultiplicationLarge) sharp(fixtures.inputPngAlphaPremultiplicationLarge)
.resize(width, height) .resize(width, heightPng)
.png({ compressionLevel: 6 }) .png({ compressionLevel: 6 })
.toBuffer(function (err) { .toBuffer(function (err) {
if (err) { if (err) {
@ -852,7 +906,7 @@ async.series({
minSamples, minSamples,
fn: function (deferred) { fn: function (deferred) {
sharp(inputPngBuffer) sharp(inputPngBuffer)
.resize(width, height) .resize(width, heightPng)
.png({ compressionLevel: 6, progressive: true }) .png({ compressionLevel: 6, progressive: true })
.toBuffer(function (err) { .toBuffer(function (err) {
if (err) { if (err) {
@ -867,7 +921,7 @@ async.series({
minSamples, minSamples,
fn: function (deferred) { fn: function (deferred) {
sharp(inputPngBuffer) sharp(inputPngBuffer)
.resize(width, height) .resize(width, heightPng)
.png({ adaptiveFiltering: true, compressionLevel: 6 }) .png({ adaptiveFiltering: true, compressionLevel: 6 })
.toBuffer(function (err) { .toBuffer(function (err) {
if (err) { if (err) {
@ -882,7 +936,7 @@ async.series({
minSamples, minSamples,
fn: function (deferred) { fn: function (deferred) {
sharp(inputPngBuffer) sharp(inputPngBuffer)
.resize(width, height) .resize(width, heightPng)
.png({ compressionLevel: 9 }) .png({ compressionLevel: 9 })
.toBuffer(function (err) { .toBuffer(function (err) {
if (err) { if (err) {