Moment

Benchmark created on


Description

Test if 'mutating' moments is faster than generating new ones.

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.4.0/moment.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Adding days to copied now
var n, time;

time = moment().startOf('month');
(function() {
  var _i, _ref, _results;
  _results = [];
  for (n = _i = 0, _ref = time.daysInMonth() - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; n = 0 <= _ref ? ++_i : --_i) {
    _results.push(moment(time).add(n, 'days'));
  }
  return _results;
})();
ready
New moment object constructor
var n, time;

time = moment();

year = time.year();

month = time.month();

(function() {
  var _i, _ref, _results;
  _results = [];
  for (n = _i = 1, _ref = time.daysInMonth(); 1 <= _ref ? _i <= _ref : _i >= _ref; n = 1 <= _ref ? ++_i : --_i) {
    _results.push(moment({
      y: year,
      M: month,
      d: n
    }));
  }
  return _results;
})();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.