Closed pawelgrzybek closed 1 year ago
This PR resolves https://github.com/NightfallRollup/nightfall-config/issues/31
How to use:
import PerformanceBenchmark from '@polygon-nightfall/common-files/utils/performance-benchmark.mjs'; // instantiate new PerformanceBenchmark const performanceBenchmark = new PerformanceBenchmark(); for (let index = 0; index < 2; index++) { performanceBenchmark.start('a'); console.log(index); performanceBenchmark.stop('a'); } for (let index = 0; index < 2; index++) { performanceBenchmark.start('b'); console.log(index); performanceBenchmark.stop('b'); } // log stats for id a console.log(JSON.stringify(performanceBenchmark.stats('a'), null, 4)); // { // "id": "a", // "count": 2, // "duration": [ // { // "start": 14.356167078018188, // "stop": 17.888582944869995, // "duration": 3.5324158668518066 // }, // { // "start": 17.892582893371582, // "stop": 17.99258303642273, // "duration": 0.10000014305114746 // } // ], // "durationMax": 3.5324158668518066, // "ducrationMin": 0.10000014305114746, // "durationMean": 1.816208004951477 // } // log stats for id a console.log(JSON.stringify(performanceBenchmark.stats('b'), null, 4)); // { // "id": "b", // "count": 2, // "duration": [ // { // "start": 13.229541063308716, // "stop": 13.251165866851807, // "duration": 0.02162480354309082 // }, // { // "start": 13.252415895462036, // "stop": 13.26924991607666, // "duration": 0.016834020614624023 // } // ], // "durationMax": 0.02162480354309082, // "ducrationMin": 0.016834020614624023, // "durationMean": 0.019229412078857422 // } // log all stats console.log(JSON.stringify(performanceBenchmark.stats(), null, 4)); // { // "a": { // "id": "a", // "count": 2, // "duration": [ // { // "start": 14.572749853134155, // "stop": 18.119667053222656, // "duration": 3.546917200088501 // }, // { // "start": 18.122957944869995, // "stop": 18.199957847595215, // "duration": 0.07699990272521973 // } // ], // "durationMax": 3.546917200088501, // "ducrationMin": 0.07699990272521973, // "durationMean": 1.8119585514068604 // }, // "b": { // "id": "b", // "count": 2, // "duration": [ // { // "start": 18.20199990272522, // "stop": 18.230082988739014, // "duration": 0.028083086013793945 // }, // { // "start": 18.231624841690063, // "stop": 18.254207849502563, // "duration": 0.0225830078125 // } // ], // "durationMax": 0.028083086013793945, // "ducrationMin": 0.0225830078125, // "durationMean": 0.025333046913146973 // } // }
This PR resolves https://github.com/NightfallRollup/nightfall-config/issues/31
How to use: