Questions tagged [performance.now]

19 questions
126
votes
3 answers

performance.now() vs Date.now()

What is the difference between performance.now() and Date.now()? Should I consider performance.now() as a replacement for Date.now() since performace.now() is more consistent and independent?
Lewis
  • 14,132
  • 12
  • 66
  • 87
68
votes
5 answers

ReferenceError: performance is not defined when using performance.now()

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 =…
Elsban
  • 1,187
  • 2
  • 13
  • 24
26
votes
2 answers

Control and measure precisely how long an image is displayed

For a reaction time study (see also this question if you're interested) we want to control and measure the display time of images. We'd like to account for the time needed to repaint on different users' machines. Edit: Originally, I used only inline…
Ruben
  • 3,452
  • 31
  • 47
15
votes
4 answers

requestAnimationFrame [now] vs performance.now() time discrepancy

Assumptions: rAF now time is calculated at the time the set of callbacks are all triggered. Therefore any blocking that happens before the first callback of that frame is called doesn't affect the rAF now and it's accurate--at least for that first…
14
votes
2 answers

How to get microsecond timings in JavaScript since Spectre and Meltdown

The situation When writing high-performance JavaScript code, the standard profiling tools offered by Chrome et al are not always sufficient. They only seem to offer function-level granularity and it can be quite time-consuming to drill down and find…
Fred Kleuver
  • 7,797
  • 2
  • 27
  • 38
11
votes
1 answer

Node.js - performance.now is not a function

I have a Node.js app. When I run node -v from the command-line, I see the following: v10.3.0 This is relevant because I'm interested in using the Performance Hooks. I've created the most basic thing I can think of, which looks like this in an in a…
Some User
  • 5,257
  • 13
  • 51
  • 93
11
votes
1 answer

Javascript's performance.now() and Nodejs

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…
Fer B.
  • 425
  • 5
  • 11
9
votes
1 answer

console.time() vs performance.now() in Node.js

I found several articles on the Internet and questions here about how to measure the code performance in Node. But I got results that differ by about two times, depending on the measurement tool. Target function is: let arr = [75, 283, 361, 168, 23,…
6
votes
3 answers

Timing with javascript performance.now()

I am trying to time the execution of my function in milliseconds. I use performance.now() in order to do that. I am able to get the time on the first run, but on the second, third, and so on runs I get 0 milliseconds. Here is an example: function…
slrom
  • 144
  • 1
  • 3
  • 11
5
votes
1 answer

How can jestjs test a function that uses performance.now()?

I'm writing a jestjs test for a ES6 class that uses performance.now(). But it doesn't seem to work. Is there a way to user perf-hooks globally from the jest.config.js? Or a way to mock performance and override it with eg Date? I've tried overriding…
Jonas
  • 53
  • 1
  • 3
4
votes
2 answers

perfomance.now() called before requestAnimationFrame - performance.now() has a larger t

So I have a simple function: var start = function(){ lastFrame = performance.now(); requestAnimationFrame((t)=>{interval(t)}); } And my interval function (just for test purposes I have clogged the values of each rAF stamp) function…
Daniel Cooke
  • 1,426
  • 12
  • 22
3
votes
4 answers

How can I convert performance.now() output to a UTC String?

In our code, we were previously calculating the difference between to events like so: var beginTime = new Date(); // Do stuff var endTime = new Date(); var duration = endTime.getTime() - beginTime.getTime(); console.log("Job began at " +…
Thunderforge
  • 19,637
  • 18
  • 83
  • 130
3
votes
1 answer

about performance.now() to test function execute time

I am currently creating a short javascript demo by myself just for inspect function performance purpose. The code is below: (function(){ 'use strict'; var getFunctionExecuteTime = function(myFoo) { if(typeof myFoo !== 'function'){ …
3
votes
0 answers

Why not use performance.now() all the time

The new performance.now() function is supposed to have better accuracy than Date.now(). All of the sites I have read seem to only use the new function for measuring execution times with the aim of finding and improving performance - because…
DavidWalley
  • 197
  • 11
2
votes
1 answer

Where do I put performance.now() calls?

I have written a small script to compare function's implementations by execution time. It runs a functon, for example, 1e6 times and sums the execution time for each call. I got puzzled as to where exactly I should place the performance.now() calls.…
curveball
  • 4,320
  • 15
  • 39
  • 49
1
2