admin管理员组

文章数量:1353147

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

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.

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

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.

Share Improve this question edited Feb 23, 2020 at 15:29 jennifer asked Feb 23, 2020 at 15:23 jenniferjennifer 7625 silver badges17 bronze badges 1
  • Does this answer your question? Node.js - performance.now is not a function – UnholySheep Commented Feb 23, 2020 at 15:28
Add a ment  | 

2 Answers 2

Reset to default 7

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

From MDN https://developer.mozilla/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.`);

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/api/perf_hooks.html.

本文标签: javascriptHow do I use performancenow()Stack Overflow