Skip to content

Commit 85dc98f

Browse files
authored
Merge pull request webpack#4813 from JLHwung/perf/date-now
Perf/use Date.now() instead of +new Date()/new Date().getTime()
2 parents c91ba49 + 6afc397 commit 85dc98f

File tree

8 files changed

+23
-23
lines changed

8 files changed

+23
-23
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/Compiler.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function Watching(compiler, watchOptions, handler) {
3636

3737
Watching.prototype._go = function() {
3838
var self = this;
39-
self.startTime = new Date().getTime();
39+
self.startTime = Date.now();
4040
self.running = true;
4141
self.invalid = false;
4242
self.compiler.applyPluginsAsync("watch-run", self, function(err) {
@@ -61,7 +61,7 @@ Watching.prototype._go = function() {
6161

6262
var stats = new Stats(compilation);
6363
stats.startTime = self.startTime;
64-
stats.endTime = new Date().getTime();
64+
stats.endTime = Date.now();
6565
self.compiler.applyPlugins("done", stats);
6666

6767
self.compiler.applyPluginsAsync("additional-pass", function(err) {
@@ -80,7 +80,7 @@ Watching.prototype._go = function() {
8080
Watching.prototype._getStats = function(compilation) {
8181
var stats = new Stats(compilation);
8282
stats.startTime = this.startTime;
83-
stats.endTime = new Date().getTime();
83+
stats.endTime = Date.now();
8484
return stats;
8585
};
8686

@@ -222,7 +222,7 @@ Compiler.prototype.watch = function(watchOptions, handler) {
222222

223223
Compiler.prototype.run = function(callback) {
224224
var self = this;
225-
var startTime = new Date().getTime();
225+
var startTime = Date.now();
226226

227227
self.applyPluginsAsync("before-run", self, function(err) {
228228
if(err) return callback(err);
@@ -239,7 +239,7 @@ Compiler.prototype.run = function(callback) {
239239
if(self.applyPluginsBailResult("should-emit", compilation) === false) {
240240
var stats = new Stats(compilation);
241241
stats.startTime = startTime;
242-
stats.endTime = new Date().getTime();
242+
stats.endTime = Date.now();
243243
self.applyPlugins("done", stats);
244244
return callback(null, stats);
245245
}
@@ -252,7 +252,7 @@ Compiler.prototype.run = function(callback) {
252252

253253
var stats = new Stats(compilation);
254254
stats.startTime = startTime;
255-
stats.endTime = new Date().getTime();
255+
stats.endTime = Date.now();
256256
self.applyPlugins("done", stats);
257257

258258
self.applyPluginsAsync("additional-pass", function(err) {
@@ -267,7 +267,7 @@ Compiler.prototype.run = function(callback) {
267267

268268
var stats = new Stats(compilation);
269269
stats.startTime = startTime;
270-
stats.endTime = new Date().getTime();
270+
stats.endTime = Date.now();
271271
self.applyPlugins("done", stats);
272272
return callback(null, stats);
273273
});

lib/ContextModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ContextModule extends Module {
9999

100100
build(options, compilation, resolver, fs, callback) {
101101
this.built = true;
102-
this.builtTime = new Date().getTime();
102+
this.builtTime = Date.now();
103103
this.resolveDependencies(fs, this.context, this.recursive, this.regExp, (err, dependencies) => {
104104
if(err) return callback(err);
105105

lib/DelegatedModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DelegatedModule extends Module {
3737

3838
build(options, compilation, resolver, fs, callback) {
3939
this.built = true;
40-
this.builtTime = new Date().getTime();
40+
this.builtTime = Date.now();
4141
this.usedExports = true;
4242
this.providedExports = this.delegateData.exports || true;
4343
this.dependencies.length = 0;

lib/ExternalModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ExternalModule extends Module {
3535
}
3636

3737
build(options, compilation, resolver, fs, callback) {
38-
this.builtTime = new Date().getTime();
38+
this.builtTime = Date.now();
3939
callback();
4040
}
4141

lib/NormalModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class NormalModule extends Module {
257257
}
258258

259259
build(options, compilation, resolver, fs, callback) {
260-
this.buildTimestamp = new Date().getTime();
260+
this.buildTimestamp = Date.now();
261261
this.built = true;
262262
this._source = null;
263263
this.error = null;

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);

lib/RawModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = class RawModule extends Module {
3636
}
3737

3838
build(options, compilations, resolver, fs, callback) {
39-
this.builtTime = new Date().getTime();
39+
this.builtTime = Date.now();
4040
callback();
4141
}
4242

0 commit comments

Comments
 (0)