<commit_before>var sharp = require("../index");
var fs = require("fs");
var path = require("path");
var imagemagick = require("imagemagick");
var imagemagickNative = require("imagemagick-native");
var gm = require("gm");
var async = require("async");
var assert = require("assert");
var Benchmark = require("benchmark");

var fixturesPath = path.join(__dirname, "fixtures");

var inputJpg = path.join(fixturesPath, "2569067123_aca715a2ee_o.jpg"); // http://www.flickr.com/photos/grizdave/2569067123/
var outputJpg = path.join(fixturesPath, "output.jpg");

var inputPng = path.join(fixturesPath, "50020484-00001.png"); // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png
var outputPng = path.join(fixturesPath, "output.png");

var inputWebp = path.join(fixturesPath, "4.webp"); // http://www.gstatic.com/webp/gallery/4.webp
var outputWebp = path.join(fixturesPath, "output.webp");

var inputTiff = path.join(fixturesPath, "G31D.TIF"); // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
var outputTiff = path.join(fixturesPath, "output.tiff");

var inputGif = path.join(fixturesPath, "Crash_test.gif"); // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif

var width = 720;
var height = 480;

// Disable libvips cache to ensure tests are as fair as they can be
sharp.cache(0);

async.series({
  jpeg: function(callback) {
    var inputJpgBuffer = fs.readFileSync(inputJpg);
    (new Benchmark.Suite("jpeg")).add("imagemagick-file-file", {
      defer: true,
      fn: function(deferred) {
        imagemagick.resize({
          srcPath: inputJpg,
          dstPath: outputJpg,
          quality: 0.8,
          width: width,
          height: height
        }, function(err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("imagemagick-native-buffer-buffer", {
      defer: true,
      fn: function(deferred) {
        imagemagickNative.convert({
          srcData: inputJpgBuffer,
          quality: 80,
          width: width,
          height: height,
					format: 'JPEG'
        });
				deferred.resolve();
      }
    }).add("gm-buffer-file", {
      defer: true,
      fn: function(deferred) {
        gm(inputJpgBuffer).resize(width, height).quality(80).write(outputJpg, function (err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("gm-buffer-buffer", {
      defer: true,
      fn: function(deferred) {
        gm(inputJpgBuffer).resize(width, height).quality(80).toBuffer(function (err, buffer) {
          if (err) {
            throw err;
          } else {
            assert.notStrictEqual(null, buffer);
            deferred.resolve();
          }
        });
      }
    }).add("gm-file-file", {
      defer: true,
      fn: function(deferred) {
        gm(inputJpg).resize(width, height).quality(80).write(outputJpg, function (err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("gm-file-buffer", {
      defer: true,
      fn: function(deferred) {
        gm(inputJpg).resize(width, height).quality(80).toBuffer(function (err, buffer) {
          if (err) {
            throw err;
          } else {
            assert.notStrictEqual(null, buffer);
            deferred.resolve();
          }
        });
      }
    }).add("sharp-buffer-file", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpgBuffer).resize(width, height).toFile(outputJpg, function(err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("sharp-buffer-buffer", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpgBuffer).resize(width, height).toBuffer(function(err, buffer) {
          if (err) {
            throw err;
          } else {
            assert.notStrictEqual(null, buffer);
            deferred.resolve();
          }
        });
      }
    }).add("sharp-file-file", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpg).resize(width, height).toFile(outputJpg, function(err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("sharp-file-buffer", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpg).resize(width, height).toBuffer(function(err, buffer) {
          if (err) {
            throw err;
          } else {
            assert.notStrictEqual(null, buffer);
            deferred.resolve();
          }
        });
      }
    }).add("sharp-file-buffer-sharpen", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpg).resize(width, height).sharpen().toBuffer(function(err, buffer) {
          if (err) {
            throw err;
          } else {<commit_msg>Add Promises benchmark<commit_after>var sharp = require("../index");
var fs = require("fs");
var path = require("path");
var imagemagick = require("imagemagick");
var imagemagickNative = require("imagemagick-native");
var gm = require("gm");
var async = require("async");
var assert = require("assert");
var Benchmark = require("benchmark");

var fixturesPath = path.join(__dirname, "fixtures");

var inputJpg = path.join(fixturesPath, "2569067123_aca715a2ee_o.jpg"); // http://www.flickr.com/photos/grizdave/2569067123/
var outputJpg = path.join(fixturesPath, "output.jpg");

var inputPng = path.join(fixturesPath, "50020484-00001.png"); // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png
var outputPng = path.join(fixturesPath, "output.png");

var inputWebp = path.join(fixturesPath, "4.webp"); // http://www.gstatic.com/webp/gallery/4.webp
var outputWebp = path.join(fixturesPath, "output.webp");

var inputTiff = path.join(fixturesPath, "G31D.TIF"); // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
var outputTiff = path.join(fixturesPath, "output.tiff");

var inputGif = path.join(fixturesPath, "Crash_test.gif"); // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif

var width = 720;
var height = 480;

// Disable libvips cache to ensure tests are as fair as they can be
sharp.cache(0);

async.series({
  jpeg: function(callback) {
    var inputJpgBuffer = fs.readFileSync(inputJpg);
    (new Benchmark.Suite("jpeg")).add("imagemagick-file-file", {
      defer: true,
      fn: function(deferred) {
        imagemagick.resize({
          srcPath: inputJpg,
          dstPath: outputJpg,
          quality: 0.8,
          width: width,
          height: height
        }, function(err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("imagemagick-native-buffer-buffer", {
      defer: true,
      fn: function(deferred) {
        imagemagickNative.convert({
          srcData: inputJpgBuffer,
          quality: 80,
          width: width,
          height: height,
					format: 'JPEG'
        });
				deferred.resolve();
      }
    }).add("gm-buffer-file", {
      defer: true,
      fn: function(deferred) {
        gm(inputJpgBuffer).resize(width, height).quality(80).write(outputJpg, function (err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("gm-buffer-buffer", {
      defer: true,
      fn: function(deferred) {
        gm(inputJpgBuffer).resize(width, height).quality(80).toBuffer(function (err, buffer) {
          if (err) {
            throw err;
          } else {
            assert.notStrictEqual(null, buffer);
            deferred.resolve();
          }
        });
      }
    }).add("gm-file-file", {
      defer: true,
      fn: function(deferred) {
        gm(inputJpg).resize(width, height).quality(80).write(outputJpg, function (err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("gm-file-buffer", {
      defer: true,
      fn: function(deferred) {
        gm(inputJpg).resize(width, height).quality(80).toBuffer(function (err, buffer) {
          if (err) {
            throw err;
          } else {
            assert.notStrictEqual(null, buffer);
            deferred.resolve();
          }
        });
      }
    }).add("sharp-buffer-file", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpgBuffer).resize(width, height).toFile(outputJpg, function(err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("sharp-buffer-buffer", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpgBuffer).resize(width, height).toBuffer(function(err, buffer) {
          if (err) {
            throw err;
          } else {
            assert.notStrictEqual(null, buffer);
            deferred.resolve();
          }
        });
      }
    }).add("sharp-file-file", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpg).resize(width, height).toFile(outputJpg, function(err) {
          if (err) {
            throw err;
          } else {
            deferred.resolve();
          }
        });
      }
    }).add("sharp-file-buffer", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpg).resize(width, height).toBuffer(function(err, buffer) {
          if (err) {
            throw err;
          } else {
            assert.notStrictEqual(null, buffer);
            deferred.resolve();
          }
        });
      }
    }).add("sharp-file-buffer-promise", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpg).resize(width, height).toBuffer().then(function(buffer) {
          assert.notStrictEqual(null, buffer);
          deferred.resolve();
        });
      }
    }).add("sharp-file-buffer-sharpen", {
      defer: true,
      fn: function(deferred) {
        sharp(inputJpg).resize(width, height).sharpen().toBuffer(function(err, buffer) {
          if (err) {
            throw err;
          } else {
{'fraction_non_alphanumeric': 0.14814814814814814, 'fraction_numerical': 0.01827549334111014, 'mean_word_length': 2.0428867199053533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6835314', 'n_tokens_mistral': 3436, 'n_tokens_neox': 3232, 'n_words': 564}