mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Tests: add squoosh-cli and squoosh-lib to performance benchmarks
This commit is contained in:
parent
551441cedd
commit
d07a549438
@ -8,6 +8,8 @@
|
|||||||
"test": "node perf && node random && node parallel"
|
"test": "node perf && node random && node parallel"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@squoosh/cli": "0.7.2",
|
||||||
|
"@squoosh/lib": "0.4.0",
|
||||||
"async": "3.2.1",
|
"async": "3.2.1",
|
||||||
"benchmark": "2.1.4",
|
"benchmark": "2.1.4",
|
||||||
"gm": "1.23.1",
|
"gm": "1.23.1",
|
||||||
@ -18,6 +20,6 @@
|
|||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "14"
|
"node": "16"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const { exec } = require('child_process');
|
||||||
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
@ -13,6 +14,7 @@ const gm = require('gm');
|
|||||||
const imagemagick = require('imagemagick');
|
const imagemagick = require('imagemagick');
|
||||||
const mapnik = require('mapnik');
|
const mapnik = require('mapnik');
|
||||||
const jimp = require('jimp');
|
const jimp = require('jimp');
|
||||||
|
const squoosh = require('@squoosh/lib');
|
||||||
|
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
@ -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
|
// mapnik
|
||||||
jpegSuite.add('mapnik-file-file', {
|
jpegSuite.add('mapnik-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user