Javascript Date subtract(days)

Description

Javascript Date subtract(days)


const times = [1000, 10000, 100000, 1000000, 5000000];
let x = 0;/*from   ww  w. j a  v  a 2  s . co  m*/

Date.prototype.subtract = function(days) {
 return new Date(this.setDate(this.getDate() - days));
}

for(i in times) {
 console.time('monkeypatch ' + times[i]);

 while (x < times[i]) {
  x++;
  let date = new Date().subtract(2);
 }

 console.timeEnd('monkeypatch ' + times[i]);
 x = 0;
}



PreviousNext

Related