Skip to content

Commit 94d0641

Browse files
committed
perf: use Date.now() instead of +new Date()
+new Date() is 2x slower than Date.now(), see https://jsperf.com/new-date-vs-date-now-vs-performance-now/6
1 parent c91ba49 commit 94d0641

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/Compilation.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class Compilation extends Tapable {
201201

202202
addModuleDependencies(module, dependencies, bail, cacheGroup, recursive, callback) {
203203
let _this = this;
204-
const start = _this.profile && +new Date();
204+
const start = _this.profile && Date.now();
205205

206206
const factories = [];
207207
for(let i = 0; i < dependencies.length; i++) {
@@ -270,7 +270,7 @@ class Compilation extends Tapable {
270270
if(!dependentModule.profile) {
271271
dependentModule.profile = {};
272272
}
273-
afterFactory = +new Date();
273+
afterFactory = Date.now();
274274
dependentModule.profile.factory = afterFactory - start;
275275
}
276276

@@ -290,7 +290,7 @@ class Compilation extends Tapable {
290290
if(!module.profile) {
291291
module.profile = {};
292292
}
293-
const time = +new Date() - start;
293+
const time = Date.now() - start;
294294
if(!module.profile.dependencies || time > module.profile.dependencies) {
295295
module.profile.dependencies = time;
296296
}
@@ -311,7 +311,7 @@ class Compilation extends Tapable {
311311
iterationDependencies(dependencies);
312312

313313
if(_this.profile) {
314-
const afterBuilding = +new Date();
314+
const afterBuilding = Date.now();
315315
module.profile.building = afterBuilding - afterFactory;
316316
}
317317

@@ -332,7 +332,7 @@ class Compilation extends Tapable {
332332
}
333333

334334
if(_this.profile) {
335-
const afterBuilding = +new Date();
335+
const afterBuilding = Date.now();
336336
dependentModule.profile.building = afterBuilding - afterFactory;
337337
}
338338

@@ -360,7 +360,7 @@ class Compilation extends Tapable {
360360
}
361361

362362
_addModuleChain(context, dependency, onModule, callback) {
363-
const start = this.profile && +new Date();
363+
const start = this.profile && Date.now();
364364

365365
const errorAndCallback = this.bail ? function errorAndCallback(err) {
366366
callback(err);
@@ -397,7 +397,7 @@ class Compilation extends Tapable {
397397
if(!module.profile) {
398398
module.profile = {};
399399
}
400-
afterFactory = +new Date();
400+
afterFactory = Date.now();
401401
module.profile.factory = afterFactory - start;
402402
}
403403

@@ -408,7 +408,7 @@ class Compilation extends Tapable {
408408
onModule(module);
409409

410410
if(this.profile) {
411-
const afterBuilding = +new Date();
411+
const afterBuilding = Date.now();
412412
module.profile.building = afterBuilding - afterFactory;
413413
}
414414

@@ -436,7 +436,7 @@ class Compilation extends Tapable {
436436
}
437437

438438
if(this.profile) {
439-
const afterBuilding = +new Date();
439+
const afterBuilding = Date.now();
440440
module.profile.building = afterBuilding - afterFactory;
441441
}
442442

lib/ProgressPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ class ProgressPlugin {
157157
state = state.replace(/^\d+\/\d+\s+/, "");
158158
if(percentage === 0) {
159159
lastState = null;
160-
lastStateTime = +new Date();
160+
lastStateTime = Date.now();
161161
} else if(state !== lastState || percentage === 1) {
162-
const now = +new Date();
162+
const now = Date.now();
163163
if(lastState) {
164164
const stateMsg = `${now - lastStateTime}ms ${lastState}`;
165165
goToLineStart(stateMsg);

0 commit comments

Comments
 (0)