How to measure the performance of a function in JavaScript

Here are 2 ways to measure the performance of a function in javascript:

```javascript
console.time('function');
function();
console.timeEnd('function');
```

or:

```javascript
const startTime = performance.now();
function();
const endTime = performance.now();
console.log(`Function took ${endTime - startTime} milliseconds`);
```

Zeno Popovici
16 Nov 2021
« Back to post