Skip to content

Commit 6afc397

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

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

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