Overview
Use a timer to speed up the process of running your code. You can give each timer a name that can run up to 10,000 timers on each page. When you call the Console.timeend () function with a timer name, the browser returns a millisecond value that indicates the time that the timer started when you called Console.timeend ().
Grammar
Console.time (Timername);
Timername
The timer name, which is used to identify a timer that stops the corresponding timer when it is called with the name Console.timeend () and outputs the timing time in the console.
How to capture a timer return value
Unfortunately, Console.time () and Console.timeend () can only output timings in the console, but cannot return the output, nor can it be assigned to a variable to be saved.
If you need to use timing as a variable, you can use the Window.performance.now () function to timing:
var start = window.performance.now (); var end = Window.performance.now (); var duration = End-start;
Window.performance.now () returns a floating-point value that indicates the millisecond of the current distance when the page was loaded, and if you want to know when the page was loaded, you can get the Window.performance.timing.navigationStart value That represents the Unix timestamp when the page was loaded.
You can also use the Date.now () function to clock, which returns an integer millisecond value.
var start = date.now (); var duration = Date.now ()-Start;
or the date (). GetTime () object, which returns a Unix timestamp:
var New Date (). GetTime (); var New Date (). GetTime (); var duration = End-start
PS:window.performance.now () is much slower than Date.now ().