Skip to content

Instantly share code, notes, and snippets.

@netroy
Created November 14, 2018 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netroy/fc6974e004a1b5e23dba11c0cd231616 to your computer and use it in GitHub Desktop.
Save netroy/fc6974e004a1b5e23dba11c0cd231616 to your computer and use it in GitHub Desktop.
Benchmark image resize modules
const sharp = require('sharp')
const Jimp = require('jimp')
const { Suite } = require('benchmark')
var suite = new Suite()
// add tests
suite
.add('Sharp', {
defer: true,
fn: deferred => {
sharp('test.jpg')
.resize({ width: 100 })
.jpeg({ quality: 60 })
// .toFile('1.jpg')
.toBuffer()
.then(() => { deferred.resolve() })
}
})
.add('Jimp', {
defer: true,
fn: deferred => {
Jimp.read('test.jpg')
.then(lenna => lenna
.resize(100, Jimp.AUTO)
.quality(60)
// .write('2.jpg')
.getBufferAsync(Jimp.MIME_JPEG)
)
.then(() => { deferred.resolve() })
}
})
// add listeners
.on('cycle', event => {
console.log(String(event.target))
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
// run async
.run({ 'async': true })
Sharp x 219 ops/sec ±1.51% (80 runs sampled)
Jimp x 1.50 ops/sec ±5.26% (12 runs sampled)
Fastest is Sharp
Sharp x 215 ops/sec ±1.08% (80 runs sampled)
Jimp x 1.45 ops/sec ±8.49% (11 runs sampled)
Fastest is Sharp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment