Refactor measure-time-taken-by-function from spread syntax to callback function

This commit is contained in:
Christopher Engels
2017-12-12 19:18:53 +01:00
parent 271130ef08
commit dcea680b08

View File

@ -4,10 +4,10 @@ Use `performance.now()` to get start and end time for the function, `console.log
First argument is the function name, subsequent arguments are passed to the function.
```js
const timeTaken = (func,...args) => {
var t0 = performance.now(), r = func(...args);
const timeTaken = callback => {
const t0 = performance.now(), r = callback();
console.log(performance.now() - t0);
return r;
}
// timeTaken(Math.pow, 2, 10) -> 1024 (0.010000000009313226 logged in console)
// timeTaken(() => Math.pow(2, 10)) -> 1024 (0.010000000009313226 logged in console)
```