I am getting an error ReferenceError: performance is not defined
when trying to use performance.now() to measure the execution time of a function call:
export async function find(someId: string, ctx: context.IContext) { try { var t0 = performance.now(); var res = someModel.find(someId, ctx.cookies); var t1 = performance.now(); console.log("Call to find took " + (t1 - t0) + " milliseconds."); return res; } catch (err) { console.error(err); throw err; } }
Any ideas how I can fix this?
The performance. now() method returns a DOMHighResTimeStamp , measured in milliseconds. The returned value represents the time elapsed since the time origin.
performance. now() is a measurement of floating point milliseconds since that particular page started to load (the performance. timing. [navigationStart](https://www.w3.org/TR/navigation-timing/#dom-performancetiming-navigationstart) timeStamp to be specific).
performance. now() has full support in all modern browsers, starting from Chrome 24, Firefox 15, and IE10.
There's no way to reset performance. now() . What you can do is to save current performance. now() when the timer starts and just substract it afterwards.
I know this is tagged front-end but if anyone comes across this looking for a node.js solution (like me), you need to first require performance from the perf_hooks module (available in node 8.5+).
const {performance} = require('perf_hooks'); const t0 = performance.now(); ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With