Merge pull request #44 from cengels/time-taken-as-callback-function
Refactor measure-time-taken-by-function from spread syntax to callback function
This commit is contained in:
@ -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)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user