diff --git a/snippets/measure-time-taken-by-function.md b/snippets/measure-time-taken-by-function.md index 8586f59d1..4b9fe33a2 100644 --- a/snippets/measure-time-taken-by-function.md +++ b/snippets/measure-time-taken-by-function.md @@ -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) ```