Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const now = () => Date.now();
- const report = {};
- const p = wrappedFunction => {
- report[wrappedFunction.name] = { min: 0, max: 0, avg: 0, callCount: 0 };
- const times = [];
- return (...args) => {
- const start = performance.now();
- const returnValue = wrappedFunction(...args);
- const end = performance.now();
- report[wrappedFunction.name].callCount++;
- const elapsed = end - start;
- times.push(elapsed);
- report[wrappedFunction.name].min = Math.min.apply(undefined, times);
- report[wrappedFunction.name].max = Math.max.apply(undefined, times);
- report[wrappedFunction.name].avg = times.reduce((p, c) => p + c, 0) / times.length;
- return returnValue;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement