add benchmark; change delta_x and rigidity to match gm

This commit is contained in:
2023-10-19 17:03:45 +03:00
parent 9ef32ef101
commit 9c3b4b9608
5 changed files with 195 additions and 2 deletions

BIN
benchmark/bear.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View 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 });