Skip to content

Commit

Permalink
Test: update benchmark dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jan 24, 2023
1 parent a532659 commit 802f560
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 19 deletions.
4 changes: 2 additions & 2 deletions test/bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "node perf && node random && node parallel"
},
"dependencies": {
"@squoosh/cli": "0.7.2",
"@squoosh/cli": "0.7.3",
"@squoosh/lib": "0.4.0",
"async": "3.2.4",
"benchmark": "2.1.4",
Expand All @@ -18,7 +18,7 @@
"semver": "7.3.8"
},
"optionalDependencies": {
"@tensorflow/tfjs-node": "4.1.0",
"@tensorflow/tfjs-node": "4.2.0",
"mapnik": "4.5.9"
},
"license": "Apache-2.0",
Expand Down
88 changes: 71 additions & 17 deletions test/bench/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const outputWebP = fixtures.path('output.webp');

const width = 720;
const height = 588;
const heightPng = 540;

// Disable libvips cache to ensure tests are as fair as they can be
sharp.cache(false);
Expand Down Expand Up @@ -648,7 +649,7 @@ async.series({
throw err;
} else {
image
.resize(width, height)
.resize(width, heightPng)
.deflateLevel(6)
.filterType(0)
.getBuffer(jimp.MIME_PNG, function (err) {
Expand All @@ -669,7 +670,7 @@ async.series({
throw err;
} else {
image
.resize(width, height)
.resize(width, heightPng)
.deflateLevel(6)
.filterType(0)
.write(outputPng, function (err) {
Expand All @@ -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 && pngSuite.add('mapnik-file-file', {
defer: true,
Expand All @@ -691,13 +745,13 @@ async.series({
if (err) throw err;
img.premultiply(function (err, img) {
if (err) throw err;
img.resize(width, height, {
img.resize(width, heightPng, {
scaling_method: mapnik.imageScaling.lanczos
}, function (err, img) {
if (err) throw err;
img.demultiply(function (err, img) {
if (err) throw err;
img.save(outputPng, 'png', function (err) {
img.save(outputPng, 'png32:f=no:z=6', function (err) {
if (err) throw err;
deferred.resolve();
});
Expand All @@ -713,13 +767,13 @@ async.series({
if (err) throw err;
img.premultiply(function (err, img) {
if (err) throw err;
img.resize(width, height, {
img.resize(width, heightPng, {
scaling_method: mapnik.imageScaling.lanczos
}, function (err, img) {
if (err) throw err;
img.demultiply(function (err, img) {
if (err) throw err;
img.encode('png', function (err) {
img.encode('png32:f=no:z=6', function (err) {
if (err) throw err;
deferred.resolve();
});
Expand All @@ -737,7 +791,7 @@ async.series({
srcPath: fixtures.inputPngAlphaPremultiplicationLarge,
dstPath: outputPng,
width: width,
height: height,
height: heightPng,
filter: 'Lanczos',
customArgs: [
'-define', 'PNG:compression-level=6',
Expand All @@ -758,7 +812,7 @@ async.series({
fn: function (deferred) {
gm(fixtures.inputPngAlphaPremultiplicationLarge)
.filter('Lanczos')
.resize(width, height)
.resize(width, heightPng)
.define('PNG:compression-level=6')
.define('PNG:compression-filter=0')
.write(outputPng, function (err) {
Expand All @@ -774,7 +828,7 @@ async.series({
fn: function (deferred) {
gm(fixtures.inputPngAlphaPremultiplicationLarge)
.filter('Lanczos')
.resize(width, height)
.resize(width, heightPng)
.define('PNG:compression-level=6')
.define('PNG:compression-filter=0')
.toBuffer(function (err) {
Expand All @@ -792,7 +846,7 @@ async.series({
minSamples,
fn: function (deferred) {
sharp(inputPngBuffer)
.resize(width, height)
.resize(width, heightPng)
.png({ compressionLevel: 6 })
.toFile(outputPng, function (err) {
if (err) {
Expand All @@ -807,9 +861,9 @@ async.series({
minSamples,
fn: function (deferred) {
sharp(inputPngBuffer)
.resize(width, height)
.resize(width, heightPng)
.png({ compressionLevel: 6 })
.toBuffer(function (err) {
.toBuffer(function (err, data) {
if (err) {
throw err;
} else {
Expand All @@ -822,7 +876,7 @@ async.series({
minSamples,
fn: function (deferred) {
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
.resize(width, height)
.resize(width, heightPng)
.png({ compressionLevel: 6 })
.toFile(outputPng, function (err) {
if (err) {
Expand All @@ -837,7 +891,7 @@ async.series({
minSamples,
fn: function (deferred) {
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
.resize(width, height)
.resize(width, heightPng)
.png({ compressionLevel: 6 })
.toBuffer(function (err) {
if (err) {
Expand All @@ -852,7 +906,7 @@ async.series({
minSamples,
fn: function (deferred) {
sharp(inputPngBuffer)
.resize(width, height)
.resize(width, heightPng)
.png({ compressionLevel: 6, progressive: true })
.toBuffer(function (err) {
if (err) {
Expand All @@ -867,7 +921,7 @@ async.series({
minSamples,
fn: function (deferred) {
sharp(inputPngBuffer)
.resize(width, height)
.resize(width, heightPng)
.png({ adaptiveFiltering: true, compressionLevel: 6 })
.toBuffer(function (err) {
if (err) {
Expand All @@ -882,7 +936,7 @@ async.series({
minSamples,
fn: function (deferred) {
sharp(inputPngBuffer)
.resize(width, height)
.resize(width, heightPng)
.png({ compressionLevel: 9 })
.toBuffer(function (err) {
if (err) {
Expand Down

0 comments on commit 802f560

Please sign in to comment.