JavaScript run time function console.time () detailed tutorial

Source: Internet
Author: User
Tags documentation

If you need to know when your code executes during Web debugging, you can use the Console.time () statement and the Console.timeend () statement to time the execution of your program in JavaScript code. Take this longer-consuming Foo () function for example:

The code is as follows Copy Code

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.time () statement before the Foo () function call, and insert the Console.timeend () statement after the end of its call:

  code is as follows copy code
console.time (" Test ");
Foo ();
Console.timeend ("test");

When the



Program finishes executing, the console displays the result of this timing: "Test:1797ms", which displays a log level of info. The

Console.time () and Console.timeend () accept a string as a parameter, which is equivalent to the timed ID. The browser will match the 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.

Browser support

for each browser, the Console.time () timing support is as follows:

Firefox. 10.0 native support. For previous versions of Firefox, this can be done by installing the Firebug plugin. See: https://developer.mozilla.org/en-US/docs/Web/API/console.time?redirectlocale=en-US&redirectslug=DOM% 2fconsole.time
Google Chrome. 2.0 native support. See: Https://developers.google.com/chrome-developer-tools/docs/console-api#consoletimelabel
IE. IE11 Central Plains students support. For previous versions of IE, it can be accomplished by installing Firebug Lite. See: Http://msdn.microsoft.com/en-us/library/ie/dn265071%28v=vs.85%29.aspx
Safari. 4.0 native support. See: Https://developer.apple.com/library/safari/documentation/AppleApplications/Conceptual/Safari_Developer_ Guide/console/console.html
Opera. Support. See: http://www.opera.com/dragonfly/documentation/console/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.