Overview
You can use a timer to speed up the process of running your code. You can give each timer a name, and you can run up to 10,000 timers on each page. When you invoke the Console.timeend () function by using the timer name, the browser returns a millisecond value that indicates when the timer starts up to the time you call Console.timeend ().
Grammar
Console.time (Timername);
Timername
A timer name used to identify a timer that, when invoked with the name Console.timeend (), stops the timer and prints the timer time on the console.
How to capture the return value of a timer
Unfortunately, Console.time () and Console.timeend () can only output the timer at the console, but not the output, and cannot be assigned to the variable save.
If you need to use timing as a variable, you can use the Window.performance.now () function to clock:
var start = Window.performance.now ();
var end = Window.performance.now ();
var duration = End-start;
Window.performance.now () returns a floating-point value indicating the millisecond time at which 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 is loaded.
You can also use the Date.now () function to time the function to return an integer millisecond value.
var start = Date.now ();
var duration = Date.now ()-Start;
or a date (). GetTime () object that returns a Unix timestamp:
var start = new Date (). GetTime ();
var end = new Date (). GetTime ();
var duration = End-start