Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript's performance.now() and Nodejs [duplicate]

I'm new to Nodejs and I'm confused about something when timing:

If Nodejs is Javascript, then why Javascript's performance.now() doesn't work on Nodejs and I'm forced to use console.time() or the like?

How can I know what other Javascript functions doesn't work on Node?

Thanks!

like image 415
Fer B. Avatar asked Jun 18 '16 16:06

Fer B.


People also ask

What does performance now () return?

The performance. now() method returns a DOMHighResTimeStamp , measured in milliseconds. The returned value represents the time elapsed since the time origin.

Is performance now faster than date now?

It's purely dependent on the time since the code started running, and clock changes do not affect the time. It's also more accurate: counting us (microseconds) instead of ms. As for support, Date. now() has slightly more support than performance.

Is Node JS good for performance?

Thanks to Node. js, customer service experience and satisfaction can be increased efficiently, easily, and at a considerably low cost. Interestingly, this runtime environment can be used on both the web server and browser sides, with many open-source modules available, which makes it even more useful and beneficial.


1 Answers

Update: Although this was correct at the time it was written, this answer is now obsolete and modern versions of Node do support performance.now()

First, we have to be very clear about what JavaScript does -- and does not include.

The definition for what JavaScript includes is the EMCA-262 guide. This is the only thing that JavaScript is required to have.

Everything else - from the DOM to the performance object are additions provided by the host environment.

Some -- many -- browsers have chosen to add performance.now() but that is NOT part of JavaScript -- just something that JavaScript can call.

nodeJS currently doesn't support it -- at least not out-of-the-box, but it looks like someone created a module that does give you that ability.

I've not tried it, just did a quick google for 'node performance.now` and this was the first hit: https://www.npmjs.com/package/performance-now

like image 184
Jeremy J Starcher Avatar answered Sep 21 '22 08:09

Jeremy J Starcher