Improved API, added first performance test

This commit is contained in:
Lovell Fuller
2013-08-20 23:55:03 +01:00
parent a4149ed2a5
commit 9ba9b95648
8 changed files with 87 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 KiB

42
tests/perf.js Executable file
View File

@@ -0,0 +1,42 @@
var sharp = require("../index");
var imagemagick = require("imagemagick");
var assert = require("assert");
// http://www.flickr.com/photos/grizdave/2569067123/
var input = __dirname + "/2569067123_aca715a2ee_o.jpg";
var output = __dirname + "/output.jpg";
var width = 640;
var height = 480;
// imagemagick
var time = process.hrtime();
imagemagick.resize({
srcPath: input,
dstPath: output,
quality: 0.75,
width: width,
height: height
}, function(err) {
if (err) {
throw err;
}
var diff = process.hrtime(time);
imagemagickTime = diff[0] * 1e9 + diff[1];
console.log("imagemagick took %d nanoseconds", imagemagickTime);
// sharp
time = process.hrtime();
sharp.crop(input, output, width, height, function(err) {
if (err) {
throw err;
}
diff = process.hrtime(time);
var sharpTime = diff[0] * 1e9 + diff[1];
console.log("sharp took %d nanoseconds", sharpTime);
// diff
assert(sharpTime < imagemagickTime, "sharp was blunt");
console.log("sharp was %d%% faster", (imagemagickTime - sharpTime) / imagemagickTime * 100);
});
});