# How to measure the performance of a function in JavaScript

> Here are 2 ways to measure the performance of a function in javascript: or:. A short Today I Learned note from the Graffino team.

- URL: https://graffino.com/til/how-to-measure-the-performance-of-a-function-in-javascript
- Author: Zeno Popovici
- Channel: command-line
- Published: 2021-11-16
- Updated: 2024-02-03

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`);
```
