Skip to content

Instantly share code, notes, and snippets.

@netroy
Created November 14, 2018 13:27
Show Gist options
  • Save netroy/fc6974e004a1b5e23dba11c0cd231616 to your computer and use it in GitHub Desktop.
Save netroy/fc6974e004a1b5e23dba11c0cd231616 to your computer and use it in GitHub Desktop.

Revisions

  1. netroy created this gist Nov 14, 2018.
    41 changes: 41 additions & 0 deletions benchmark-resize.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    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 })
    3 changes: 3 additions & 0 deletions output-buffer.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Sharp x 219 ops/sec ±1.51% (80 runs sampled)
    Jimp x 1.50 ops/sec ±5.26% (12 runs sampled)
    Fastest is Sharp
    3 changes: 3 additions & 0 deletions output-file.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Sharp x 215 ops/sec ±1.08% (80 runs sampled)
    Jimp x 1.45 ops/sec ±8.49% (11 runs sampled)
    Fastest is Sharp