Build README
This commit is contained in:
@ -385,15 +385,15 @@ const last = arr => arr.slice(-1)[0];
|
|||||||
### Measure time taken by function
|
### Measure time taken by function
|
||||||
|
|
||||||
Use `performance.now()` to get start and end time for the function, `console.log()` the time taken.
|
Use `performance.now()` to get start and end time for the function, `console.log()` the time taken.
|
||||||
First argument is the function name, subsequent arguments are passed to the function.
|
Pass a callback function as the argument.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const timeTaken = (func,...args) => {
|
const timeTaken = callback => {
|
||||||
var t0 = performance.now(), r = func(...args);
|
const t0 = performance.now(), r = callback();
|
||||||
console.log(performance.now() - t0);
|
console.log(performance.now() - t0);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
// timeTaken(Math.pow, 2, 10) -> 1024 (0.010000000009313226 logged in console)
|
// timeTaken(() => Math.pow(2, 10)) -> 1024 (0.010000000009313226 logged in console)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Median of array of numbers
|
### Median of array of numbers
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
### Measure time taken by function
|
### Measure time taken by function
|
||||||
|
|
||||||
Use `performance.now()` to get start and end time for the function, `console.log()` the time taken.
|
Use `performance.now()` to get start and end time for the function, `console.log()` the time taken.
|
||||||
First argument is the function name, subsequent arguments are passed to the function.
|
Pass a callback function as the argument.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const timeTaken = callback => {
|
const timeTaken = callback => {
|
||||||
|
|||||||
Reference in New Issue
Block a user