Replaced 'new Date().getTime()' calls with 'Date.now()' for clarity and performance

This commit is contained in:
n1474335 2020-03-12 15:23:22 +00:00
parent 9d09146f68
commit 75da5b650c
5 changed files with 12 additions and 12 deletions

View File

@ -39,7 +39,7 @@ class Chef {
*/
async bake(input, recipeConfig, options) {
log.debug("Chef baking");
const startTime = new Date().getTime(),
const startTime = Date.now(),
recipe = new Recipe(recipeConfig),
containsFc = recipe.containsFlowControl(),
notUTF8 = options && "treatAsUtf8" in options && !options.treatAsUtf8;
@ -84,7 +84,7 @@ class Chef {
result: await this.dish.get(returnType, notUTF8),
type: Dish.enumLookup(this.dish.type),
progress: progress,
duration: new Date().getTime() - startTime,
duration: Date.now() - startTime,
error: error
};
}
@ -110,7 +110,7 @@ class Chef {
silentBake(recipeConfig) {
log.debug("Running silent bake");
const startTime = new Date().getTime(),
const startTime = Date.now(),
recipe = new Recipe(recipeConfig),
dish = new Dish();
@ -119,7 +119,7 @@ class Chef {
} catch (err) {
// Suppress all errors
}
return new Date().getTime() - startTime;
return Date.now() - startTime;
}

View File

@ -144,7 +144,7 @@ class MultipleBombe extends Operation {
* @param {number} progress - Progress (as a float in the range 0..1)
*/
updateStatus(nLoops, nStops, progress, start) {
const elapsed = new Date().getTime() - start;
const elapsed = Date.now() - start;
const remaining = (elapsed / progress) * (1 - progress) / 1000;
const hours = Math.floor(remaining / 3600);
const minutes = `0${Math.floor((remaining % 3600) / 60)}`.slice(-2);
@ -237,7 +237,7 @@ class MultipleBombe extends Operation {
const totalRuns = choose(rotors.length, 3) * 6 * fourthRotors.length * reflectors.length;
let nRuns = 0;
let nStops = 0;
const start = new Date().getTime();
const start = Date.now();
for (const rotor1 of rotors) {
for (const rotor2 of rotors) {
if (rotor2 === rotor1) {

View File

@ -70,7 +70,7 @@ if (typeof document !== 'undefined') {
try {
// Mouse move event to fill random array
document.addEventListener('mousemove', function (e) {
randomRing.set((new Date().getTime() & 255) ^
randomRing.set((Date.now() & 255) ^
((e.clientX || e.pageX) & 255) ^
((e.clientY || e.pageY) & 255));
}, false);
@ -80,7 +80,7 @@ if (typeof document !== 'undefined') {
try {
// Keypress event to fill random array
document.addEventListener('keydown', function (e) {
randomRing.set((new Date().getTime() & 255) ^
randomRing.set((Date.now() & 255) ^
(e.keyCode & 255));
}, false);
} catch (e) {

View File

@ -37,7 +37,7 @@ class WindowWaiter {
* focus is returned.
*/
windowBlur() {
this.windowBlurTime = new Date().getTime();
this.windowBlurTime = Date.now();
}
@ -52,7 +52,7 @@ class WindowWaiter {
* a long time and the browser has swapped out all its memory.
*/
windowFocus() {
const unfocusedTime = new Date().getTime() - this.windowBlurTime;
const unfocusedTime = Date.now() - this.windowBlurTime;
if (unfocusedTime > 60000) {
this.app.silentBake();
}

View File

@ -375,7 +375,7 @@ class WorkerWaiter {
*/
bakingComplete() {
this.setBakingStatus(false);
let duration = new Date().getTime() - this.bakeStartTime;
let duration = Date.now() - this.bakeStartTime;
duration = duration.toLocaleString() + "ms";
const progress = this.getBakeProgress();
@ -489,7 +489,7 @@ class WorkerWaiter {
bake(recipeConfig, options, progress, step) {
this.setBakingStatus(true);
this.manager.recipe.updateBreakpointIndicator(false);
this.bakeStartTime = new Date().getTime();
this.bakeStartTime = Date.now();
this.bakeId++;
this.recipeConfig = recipeConfig;
this.options = options;