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 days, n, time;

time = moment();

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

alert(days.length);
ready
New moment object constructor
time = moment();

year = time.year();

month = time.month();

days = (function() {
  var _i, _ref, _results;
  _results = [];
  for (n = _i = 0, _ref = time.daysInMonth(); 0 <= _ref ? _i <= _ref : _i >= _ref; n = 0 <= _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.