<commit_before>var async = require('async');

/**
 * Consumes memory over time.
 * @param {Number} options.bytes The amount of memory to consume, in byts.
 * @param {Number} options.time The number of milliseconds over which to consume memory.
 * @param {Number} options.increments The number of allocations that will occur.
 * @param {Function} callback Callback handling the response.
 */
module.exports = function(options, callback) {

  options = options || {};
  options.bytes = options.bytes || 1;
  options.time = options.time || 1;
  options.increments = options.increments || 1;
  options.debug = options.debug || false;

  var buffers = [];

  var increments = options.increments;
  var incrementAmount = Math.floor(options.bytes / increments);
  var incrementTime = Math.floor(options.time / increments);
  var count = 0;

  async.whilst(
    function() { return count < increments; },
    function(callback) {
      count++;
      setTimeout(allocate, incrementTime * count, options, count, incrementAmount, buffers, callback);
    },
    function() { callback(null, buffers); });
};

/**
 * Allocates a buffer to the specified size.
 * @param {Number} bytes The number of bytes to allocate.
 */
var allocate = function(options, increment, bytes, buffers, callback) {

  if(options.debug) {
    console.log('Increment ' + increment + ' allocating ' + bytes + ' bytes.');
  }

  var buffer = new Buffer(bytes);
  buffer.fill('h');
  buffers.push(buffer);

  callback();
};

// Helpers when specifying amount to bleed(),
module.exports.ONE_KILOBYTE = 1024;
module.exports.ONE_MEGABYTE = module.exports.ONE_KILOBYTE * 1024;<commit_msg>Fixed logic in allocation loop to use correct delay.<commit_after>var async = require('async');

/**
 * Consumes memory over time.
 * @param {Number} options.bytes The amount of memory to consume, in byts.
 * @param {Number} options.time The number of milliseconds over which to consume memory.
 * @param {Number} options.increments The number of allocations that will occur.
 * @param {Function} callback Callback handling the response.
 */
module.exports = function(options, callback) {

  options = options || {};
  options.bytes = options.bytes || 1;
  options.time = options.time || 1;
  options.increments = options.increments || 1;
  options.debug = options.debug || false;

  var buffers = [];

  var increments = options.increments;
  var incrementAmount = Math.floor(options.bytes / increments);
  var incrementTime = Math.floor(options.time / increments);
  var count = 0;

  async.whilst(
    function() { return count < increments; },
    function(callback) {
      count++;
      setTimeout(allocate, incrementTime, options, count, incrementAmount, buffers, callback);
    },
    function() { callback(null, buffers); });
};

/**
 * Allocates a buffer to the specified size.
 * @param {Number} bytes The number of bytes to allocate.
 */
var allocate = function(options, increment, bytes, buffers, callback) {

  if(options.debug) {
    console.log('Increment ' + increment + ' allocating ' + bytes + ' bytes.');
  }

  var buffer = new Buffer(bytes);
  buffer.fill('h');
  buffers.push(buffer);

  callback();
};

// Helpers when specifying amount to bleed(),
module.exports.ONE_KILOBYTE = 1024;
module.exports.ONE_MEGABYTE = module.exports.ONE_KILOBYTE * 1024;
{'fraction_non_alphanumeric': 0.12835191322687556, 'fraction_numerical': 0.0072310937029225674, 'mean_word_length': 3.9258160237388724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2662594', 'n_tokens_mistral': 991, 'n_tokens_neox': 937, 'n_words': 296}