// Generated by CoffeeScript 1.12.7
(function() {
  var stopwatch, timeOperationAsync, timeOperationPromised, timeOperationSync;

  stopwatch = require('./stopwatch');

  timeOperationSync = function(operation) {
    var watch;
    watch = stopwatch["new"]().start();
    operation();
    return watch.stop().duration();
  };

  timeOperationAsync = function(operation, callback) {
    var next, watch;
    watch = stopwatch["new"]();
    if (typeof callback === 'function') {
      next = function() {
        return callback(watch.stop().duration());
      };
      watch.start();
      operation(next);
      return void 0;
    } else {
      return new Promise(function(resolve, reject) {
        next = function(error) {
          if (error != null) {
            return reject(error);
          } else {
            return resolve(watch.stop().duration());
          }
        };
        watch.start();
        return operation(next);
      });
    }
  };

  timeOperationPromised = function(operation, callback) {
    var watch;
    watch = stopwatch["new"]();
    if (typeof callback === 'function') {
      watch.start();
      operation().then(function() {
        return callback(watch.stop().duration());
      });
      return void 0;
    } else {
      watch.start();
      return operation().then(function() {
        return watch.stop().duration();
      });
    }
  };

  module.exports = {
    time: timeOperationSync,
    timeAsync: timeOperationAsync,
    timePromised: timeOperationPromised
  };

}).call(this);
