If you need to know the time when the code is executed during web debugging, you can time the execution of the program by adding console.time() statements and console.timeEnd() statements in the JavaScript code. Take the following lengthy foo() function as an example:
If you need to know how long it takes to execute a function, you can insert a console.time() statement before the foo() function call and a console.timeEnd() statement after the call ends:
After the program is executed, the console will display the result of this timing: "test: 1797ms", and the displayed log level is info.
console.time() and console.timeEnd() accept a string as a parameter, which is equivalent to the timing id. The browser will pair console.time() with the same parameter (id) and console.timeEnd() and record the time difference between the two. Therefore, it is possible to time different places in a JavaScript program by using different ids.
Browser support
For each browser, console.time() timing support is as follows:
Firefox. Native support after 10.0. For previous versions of Firefox, this can be achieved by installing the Firebug plug-in. For details, see: https://developer.mozilla.org/en-US/docs/Web/API/console.time?redirectlocale=en-US&redirectslug=DOM/console.time
Google Chrome. Native support after 2.0. For details, see: https://developers.google.com/chrome-developer-tools/docs/console-api#consoletimelabel
ie. Supported natively in IE11. For previous versions of IE, this can be achieved by installing Firebug Lite. For details, see: http://msdn.microsoft.com/en-us/library/ie/dn265071(v=vs.85).aspx
Safari. Native support after 4.0. For details, see: https://developer.apple.com/library/safari/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/Console/Console.html
Opera. support. For details, see: http://www.opera.com/dragonfly/documentation/console/