1

I would like to use performance.now() as seen in the top answer to this SO Post.

How to measure time taken by a function to execute

However is it was not available in my Replit or my local Node server.

Do I have to install it?

I searched packages on Repl.it and this came up

enter image description here

In the repl.it I added ...

const performance = require('performance'); const t0 = performance.now();

and it auto installed performance but I am still getting an error ... now it is saying that now() is not a function.

jennifer
  • 682
  • 5
  • 14
  • Does this answer your question? [Node.js - performance.now is not a function](https://stackoverflow.com/questions/50646279/node-js-performance-now-is-not-a-function) – UnholySheep Feb 23 '20 at 15:28

2 Answers2

4

It's part of the browser's javascript API, no 3rd party is needed.

From MDN https://developer.mozilla.org/en-US/docs/Web/API/Performance/now:

The returned value represents the time elapsed since the time origin.

Usage example:

const t0 = performance.now();
doSomething();
const t1 = performance.now();
console.log(`Call to doSomething took ${t1 - t0} milliseconds.`);
novalagung
  • 10,905
  • 4
  • 58
  • 82
0

no installation it's part of the node api. Your best answer, by far, will be to look at the thorough documentation here - https://nodejs.org/api/perf_hooks.html.

Louis
  • 1,194
  • 1
  • 10
  • 15