Created
May 22, 2018 21:47
-
-
Save bontscho/f1039d669f364075020362a776cf21d8 to your computer and use it in GitHub Desktop.
benchmark for pixelmatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const Benchmark = require('benchmark'); | |
const suite = new Benchmark.Suite; | |
const PNG = require('pngjs').PNG, | |
matchAfter = require('./'), | |
matchBefore = require('./index.1.js'); | |
const img1 = readImage(process.argv[2]); | |
const img2 = readImage(process.argv[3]); | |
const diff = new PNG({width: img1.width, height: img1.height}); | |
const array1 = randomizeArray(150*150*4); | |
const array2 = randomizeArray(150*150*4); | |
suite | |
.add('before # Buffer(includeDiffOnDataEquality=true)', function() { | |
const mismatch = matchBefore(img1.data, img2.data, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: true | |
}); | |
}) | |
.add('after # Buffer(includeDiffOnDataEquality=true)', function() { | |
const mismatch = matchAfter(img1.data, img2.data, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: true | |
}); | |
}) | |
.add('before # Buffer(includeDiffOnDataEquality=false)', function() { | |
const mismatch = matchBefore(img1.data, img2.data, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: false | |
}); | |
}) | |
.add('after # Buffer(includeDiffOnDataEquality=false)', function() { | |
const mismatch = matchAfter(img1.data, img2.data, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: false | |
}); | |
}) | |
.add('before # identical Arrays (includeDiffOnDataEquality=false)', function() { | |
const mismatch = matchBefore(array1, array1, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: false | |
}); | |
}) | |
.add('after # identical Arrays (includeDiffOnDataEquality=false)', function() { | |
const mismatch = matchAfter(array1, array1, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: false | |
}); | |
}) | |
.add('before # identical Arrays (includeDiffOnDataEquality=true)', function() { | |
const mismatch = matchBefore(array1, array1, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: true | |
}); | |
}) | |
.add('after # identical Arrays (includeDiffOnDataEquality=true)', function() { | |
const mismatch = matchAfter(array1, array1, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: true | |
}); | |
}) | |
.add('before # different Arrays', function() { | |
const mismatch = matchBefore(array1, array2, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: false | |
}); | |
}) | |
.add('after # different Arrays', function() { | |
const mismatch = matchAfter(array1, array2, diff.data, diff.width, diff.height, { | |
includeDiffOnDataEquality: false | |
}); | |
}) | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}). | |
on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}). | |
run(); | |
function readImage(name) { | |
const data = fs.readFileSync(path.join(__dirname, 'test/fixtures/' + name + '.png')); | |
return PNG.sync.read(data); | |
} | |
function randomizeArray(length) { | |
const data = []; | |
for (let i = 0; i < length; i++) { | |
const randomNumber = Math.floor(Math.random()*256); | |
data.push(randomNumber); | |
} | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment