From 89a548b344083484ccd5e9c7cf438b49fcf279e1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Sep 2019 15:51:16 +0200 Subject: [PATCH] Performance Research Tools Implemented --- Animation.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Animation.js b/Animation.js index 355d5633a..400efe5c9 100644 --- a/Animation.js +++ b/Animation.js @@ -25,6 +25,9 @@ function newAnimation () { finalize: finalize } + let totalConsumption = 0 + let totalCounter = 0 + return thisObject function finalize () { @@ -76,10 +79,12 @@ function newAnimation () { let randomNumber let mustExecute + // console.clear() + for (const [key, callBackFunction] of callBackFunctions.entries()) { switch (key) { case 'Floating Space Physics': - chanceToExecute = 100 + chanceToExecute = 50 randomNumber = Math.random() * 100 * chanceToExecute if (randomNumber > 100 - chanceToExecute) { mustExecute = true } else { mustExecute = false } break @@ -93,6 +98,17 @@ function newAnimation () { callBackFunction() let t1 = performance.now() let timeConsumed = t1 - t0 + if (key === 'Chart Space Draw') { + // console.log(key, (totalConsumption / totalCounter).toFixed(1)) + + if (Math.random() * 100 > 99) { + totalConsumption = 0 + totalCounter = 0 + } + + totalConsumption = totalConsumption + timeConsumed + totalCounter = totalCounter + 1 + } performanceMap.set(key, timeConsumed) totalTimeConsumed = totalTimeConsumed + timeConsumed totalElements++ @@ -100,10 +116,12 @@ function newAnimation () { } /* Performance Check */ - console.clear() + for (const [key, timeConsumed] of performanceMap.entries()) { let percentage = timeConsumed * 100 / totalTimeConsumed - console.log(key, percentage.toFixed(2)) + if (key === 'Chart Space Draw') { + // console.log(key, percentage.toFixed(0)) + } } } else { browserCanvas.width = 1