jquery Operation DOM Efficiency test------HTML and append insert document

Source: Internet
Author: User

$(function () {        varHtmlresult = createhtmlcontent (100); Console.log (Htmlresult) Inserthtml.call ($ ("#left"), "HTML () time consuming:", Htmlresult); Inserthtml.call ($ ("#right"), "append () Time-consuming:", Htmlresult);    }); functionCreatehtmlcontent (count) {varHtmlcontent = "";  for(vari = 0; I < count; i++) {htmlcontent+ = ' <div> This is the first ${i + 1} elements </div> ';        }        returnhtmlcontent; }    functioninserthtml (Type, htmlcontent) {console.time (type); if(Type = = = "html () time-consuming:") {             This. HTML (htmlcontent); } Else if(Type = = = "Append () Time-consuming:") {             This. Empty (). append (htmlcontent);    } console.timeend (type); }

100 Data Set Test results:

HTML () Time consuming:: 0.69921875ms
jqueryapitest.html:46 append () Time:: 1.571044921875ms

1000 Data Set test results:

HTML () Time consuming:: 3.281982421875ms
jqueryapitest.html:46 append () Time:: 9.39111328125ms

10,000 Data Set test results

HTML () Time consuming:: 26.7099609375ms
jqueryapitest.html:46 append () Time:: 51.161865234375ms

jquery Operation DOM Efficiency test------HTML and append insert document

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.