1

I want to be ensure about the equation of DomContentLoaded time in seconds?

This equation can help me ?

DomContentLoaded = performanceTiming.domContentLoadedEventEnd - performanceTiming.navigationStart

Weam Jalal
  • 11
  • 1

1 Answers1

0

How to measure time taken by a function to execute

Check this in regards to measuring the time your functions take

In your function that you want to measure the performance of, use the node built in time checkers

function doPuppeteerStuff = () => {
  console.time('puppeteer');
  
  //doPuppeteerMagic()
  
  console.timeEnd('puppeteer');
  // Prints: puppeteer: 225.438ms
}

https://nodejs.org/api/console.html#console_console_timeend_label Here is the documentation for it

Ruben Verster
  • 301
  • 1
  • 8
  • Just I want to ensure if I use the right equation – Weam Jalal Mar 29 '22 at 09:29
  • Oh. Yeah. That's the correct equaton. timeTaken = timeEnd - timeStart :) – Ruben Verster Mar 29 '22 at 09:30
  • not performanceTiming.domContentLoadedEventEnd - performanceTiming.navigationStart? – Weam Jalal Mar 29 '22 at 09:32
  • performanceTiming.domContentLoadedEventEnd - performanceTiming.navigationStart Is correct, but it is legacy code. You must try not to use it... What you can however do is in the function that you are trying to measure the performance of, have the console.time and console.timeEnd helpers I'm going to edit my answer – Ruben Verster Mar 29 '22 at 09:36
  • So it is not give me the accurate values? – Weam Jalal Mar 29 '22 at 09:41
  • It should give accurate values, but this is very old code to use and is not recommended. Come look here for help on a better way of using this: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming/domContentLoadedEventEnd – Ruben Verster Mar 29 '22 at 09:44
  • If i use timeEnd - timeStart it is not give a correct answer – Weam Jalal Mar 29 '22 at 09:49
  • Obvious... because it isn't a real thing you can use... I just made an example... Communication barrier man... – Ruben Verster Mar 30 '22 at 14:08