add benchmark; change delta_x and rigidity to match gm
This commit is contained in:
BIN
benchmark/bear.png
Normal file
BIN
benchmark/bear.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
43
benchmark/liquid_rescale.js
Normal file
43
benchmark/liquid_rescale.js
Normal file
@ -0,0 +1,43 @@
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs');
|
||||
const concolor = require('concolor');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const { liquidRescale } = require('../dist/index.js');
|
||||
const { Suite } = require('benchmark');
|
||||
|
||||
const image = fs.readFileSync(path.join(path.resolve(), 'benchmark', 'bear.png'));
|
||||
const suite = new Suite("Liquid rescale and resize image");
|
||||
|
||||
function liquidRescaleWithGm() {
|
||||
return new Promise((resolve, reject) => {
|
||||
gm(image).size((err, size) => {
|
||||
if (err) reject(err);
|
||||
|
||||
const width = size.width;
|
||||
const height = size.height;
|
||||
|
||||
gm(image).out('-liquid-rescale', "400x400")
|
||||
.toBuffer('JPEG', (err, buf) => {
|
||||
if (err) reject(err);
|
||||
|
||||
gm(buf).resize(width, height)
|
||||
.toBuffer('JPEG', (err, buf) => {
|
||||
err ? reject(err) : resolve(buf);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
suite
|
||||
.add('gm', async () => {
|
||||
await liquidRescaleWithGm();
|
||||
})
|
||||
.add('native', async () => {
|
||||
await liquidRescale(image, 400, 400);
|
||||
})
|
||||
.on('cycle', (event) => console.info(String(event.target)))
|
||||
.on('complete', function () {
|
||||
console.info(`${this.name} bench suite: Fastest is ${concolor`${this.filter('fastest').map('name')}(green)`}`);
|
||||
})
|
||||
.run({ async: true });
|
Reference in New Issue
Block a user