// Generated by CoffeeScript 1.7.1
(function() {
  var csv, fs, generator, w;

  fs = require('fs');

  csv = require('..');

  generator = csv.generator;

  switch (process.argv[2]) {
    case 'csv':
      w = generator({
        start: true
      }).pipe(csv().to.path("" + __dirname + "/perf.out"));
      break;
    case 'fs':
      w = generator({
        start: true
      }).pipe(fs.createWriteStream("" + __dirname + "/perf.out", {
        flags: 'w'
      }));
      break;
    case 'null':
      w = generator({
        start: true
      }).pipe(csv().to.path("/dev/null"));
      break;
    case 'stdout':
      w = generator({
        start: true
      }).pipe(process.stdout);
      break;
    default:
      return console.log('coffee sample/perf.coffee [action] where action is "csv", "fs" or "stdout"');
  }

  (function(fn) {
    var last_length, last_time, length, size;
    length = 0;
    last_length = 0;
    last_time = Date.now();
    size = 0;
    return w.write = function(data) {
      var memory, s, speed;
      length += data.length;
      last_length += data.length;
      s = Math.floor(length / 1024 / 1024);
      speed = last_length / 1024 / 1024 / ((Date.now() - last_time) / 1000);
      speed = Math.round(speed * 100) / 100;
      memory = process.memoryUsage().rss / 1024 / 1024;
      memory = Math.round(memory * 100) / 100;
      if (s > size) {
        console.log("Size: " + s + " Mo; Speed: " + speed + " Mo/s; Memory: " + memory + " Mo");
        size = s;
        last_time = Date.now();
        last_length = 0;
      }
      return fn.apply(this, arguments);
    };
  })(w.write);

}).call(this);

//# sourceMappingURL=perf.map
