This article mainly introduces the console in JavaScript. time () function details, console. the time () function is mainly used to count the execution time of a program. If you need to know the code execution time during Web debugging, you can add a console to the JavaScript code. time () Statement and console. timeEnd () statement to timing program execution. The following is an example of the time-consuming foo () function:
Function foo () {var x = 4.237; var y = 0; for (var I = 0; I <100000000; I ++) {y = y + x * x ;} return y ;}
If you need to know how long it takes to execute a function, you can insert the console before calling the foo () function. time () Statement, which is inserted into the console after the call is completed. timeEnd () Statement:
Console. time ("test"); foo (); console. timeEnd ("test ");
After the program is executed, the console displays the timing Result: "test: 1797ms" and the log level is info.
Console. time () and console. timeEnd () accept a string as the parameter, which is equivalent to the timing id. The browser will pair console. time () with the same parameter (id) with console. timeEnd () to record the time difference between the two. Therefore, you can use different IDs to timing different places in JavaScript programs.
For more information about the console. time () function in JavaScript, see the Chinese PHP website!