Skip to content

Commit

Permalink
Tests: add squoosh-cli and squoosh-lib to performance benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Aug 16, 2021
1 parent 551441c commit d07a549
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"test": "node perf && node random && node parallel"
},
"devDependencies": {
"@squoosh/cli": "0.7.2",
"@squoosh/lib": "0.4.0",
"async": "3.2.1",
"benchmark": "2.1.4",
"gm": "1.23.1",
Expand All @@ -18,6 +20,6 @@
},
"license": "Apache-2.0",
"engines": {
"node": "14"
"node": "16"
}
}
61 changes: 61 additions & 0 deletions test/bench/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const os = require('os');
const fs = require('fs');
const { exec } = require('child_process');

const async = require('async');
const assert = require('assert');
Expand All @@ -13,6 +14,7 @@ const gm = require('gm');
const imagemagick = require('imagemagick');
const mapnik = require('mapnik');
const jimp = require('jimp');
const squoosh = require('@squoosh/lib');

const fixtures = require('../fixtures');

Expand Down Expand Up @@ -75,6 +77,65 @@ async.series({
});
}
});
// squoosh-cli
jpegSuite.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":${height},"method":"lanczos3","premultiply":false,"linearRGB":false}' \
--mozjpeg '{"quality":80,"progressive":false,"optimize_coding":true,"quant_table":0,"trellis_multipass":false,"chroma_subsample":2,"separate_chroma_quality":false}' \
"${fixtures.inputJpg}"`, function (err) {
if (err) {
throw err;
}
deferred.resolve();
});
}
});
// squoosh-lib (GPLv3)
jpegSuite.add('squoosh-lib-buffer-buffer', {
defer: true,
fn: function (deferred) {
const pool = new squoosh.ImagePool();
const image = pool.ingestImage(inputJpgBuffer);
image.decoded
.then(function () {
return image.preprocess({
resize: {
enabled: true,
width,
height,
method: 'lanczos3',
premultiply: false,
linearRGB: false
}
});
})
.then(function () {
return image.encode({
mozjpeg: {
quality: 80,
progressive: false,
optimize_coding: true,
quant_table: 0,
trellis_multipass: false,
chroma_subsample: 2,
separate_chroma_quality: false
}
});
})
.then(function () {
return pool.close();
})
.then(function () {
return image.encodedWith.mozjpeg;
})
.then(function () {
deferred.resolve();
});
}
});
// mapnik
jpegSuite.add('mapnik-file-file', {
defer: true,
Expand Down

0 comments on commit d07a549

Please sign in to comment.