Add timing

This commit is contained in:
schmelczerandras 2020-07-16 22:32:56 +02:00
parent 039f7e8cef
commit 1ac4113b0d
2 changed files with 27 additions and 2 deletions

View file

@ -0,0 +1,22 @@
export const TimeIt = (func, interval = 60) => {
let i = 0;
let values = [];
return () => {
const start = performance.now();
func();
const end = performance.now();
values.push(end - start);
if (++i % interval == 0) {
values.sort();
console.log(
`${func.name}\n\tMax ${values[values.length - 1].toFixed(
2
)} ms\n\tMedian ${values[Math.floor(values.length / 2)].toFixed(2)} ms`
);
values = [];
}
};
};