Skip to content

Commit

Permalink
perf: use Date.now() instead of new Date().getTime()
Browse files Browse the repository at this point in the history
new Date().getTime() is 2x slower than Date.now(), see https://jsperf.com/new-date-vs-date-now-vs-performance-now/6
  • Loading branch information
JLHwung committed May 4, 2017
1 parent 94d0641 commit 6afc397
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Watching(compiler, watchOptions, handler) {

Watching.prototype._go = function() {
var self = this;
self.startTime = new Date().getTime();
self.startTime = Date.now();
self.running = true;
self.invalid = false;
self.compiler.applyPluginsAsync("watch-run", self, function(err) {
Expand All @@ -61,7 +61,7 @@ Watching.prototype._go = function() {

var stats = new Stats(compilation);
stats.startTime = self.startTime;
stats.endTime = new Date().getTime();
stats.endTime = Date.now();
self.compiler.applyPlugins("done", stats);

self.compiler.applyPluginsAsync("additional-pass", function(err) {
Expand All @@ -80,7 +80,7 @@ Watching.prototype._go = function() {
Watching.prototype._getStats = function(compilation) {
var stats = new Stats(compilation);
stats.startTime = this.startTime;
stats.endTime = new Date().getTime();
stats.endTime = Date.now();
return stats;
};

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

Compiler.prototype.run = function(callback) {
var self = this;
var startTime = new Date().getTime();
var startTime = Date.now();

self.applyPluginsAsync("before-run", self, function(err) {
if(err) return callback(err);
Expand All @@ -239,7 +239,7 @@ Compiler.prototype.run = function(callback) {
if(self.applyPluginsBailResult("should-emit", compilation) === false) {
var stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = new Date().getTime();
stats.endTime = Date.now();
self.applyPlugins("done", stats);
return callback(null, stats);
}
Expand All @@ -252,7 +252,7 @@ Compiler.prototype.run = function(callback) {

var stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = new Date().getTime();
stats.endTime = Date.now();
self.applyPlugins("done", stats);

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

var stats = new Stats(compilation);
stats.startTime = startTime;
stats.endTime = new Date().getTime();
stats.endTime = Date.now();
self.applyPlugins("done", stats);
return callback(null, stats);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/ContextModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ContextModule extends Module {

build(options, compilation, resolver, fs, callback) {
this.built = true;
this.builtTime = new Date().getTime();
this.builtTime = Date.now();
this.resolveDependencies(fs, this.context, this.recursive, this.regExp, (err, dependencies) => {
if(err) return callback(err);

Expand Down
2 changes: 1 addition & 1 deletion lib/DelegatedModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DelegatedModule extends Module {

build(options, compilation, resolver, fs, callback) {
this.built = true;
this.builtTime = new Date().getTime();
this.builtTime = Date.now();
this.usedExports = true;
this.providedExports = this.delegateData.exports || true;
this.dependencies.length = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/ExternalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ExternalModule extends Module {
}

build(options, compilation, resolver, fs, callback) {
this.builtTime = new Date().getTime();
this.builtTime = Date.now();
callback();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/NormalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class NormalModule extends Module {
}

build(options, compilation, resolver, fs, callback) {
this.buildTimestamp = new Date().getTime();
this.buildTimestamp = Date.now();
this.built = true;
this._source = null;
this.error = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/RawModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = class RawModule extends Module {
}

build(options, compilations, resolver, fs, callback) {
this.builtTime = new Date().getTime();
this.builtTime = Date.now();
callback();
}

Expand Down

0 comments on commit 6afc397

Please sign in to comment.