I’m wrapping a huge amount of HTML by $() It takes about 250 ms.
What affects the performance: the length of the html string, or the number of elements in the html string ?
I’m wrapping a huge amount of HTML by $() It takes about 250 ms.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both, but the number of elements has a much bigger impact than the string length.
The longer the string, the more that will be needed to parse it.
The higher the number of elements that need to be created, the longer it will take.
If you’re really curious, why not create a jsPerf test case? In the first test, you could have a single paragraph with a lot of text content, and in a second test you could place multiple
<p>elements with no content. Make sure both strings have the same length.Update: I’ve created an example jsPerf test case that demonstrates that the number of elements is indeed much more important than the string length. http://jsperf.com/jquery-htmlstring