Why is this code's execution speed so different?

Posted by Steve Watkins on Stack Overflow See other posts from Stack Overflow or by Steve Watkins
Published on 2011-01-14T22:20:30Z Indexed on 2011/01/14 22:53 UTC
Read the original article Hit count: 274

Filed under:
|

In Internet Explorer 7, this code executes consistently in 47 ms:

function updateObjectValues() {    
    $('.objects').html(12345678); // ~500 DIVs
}

however, this code executes consistently in 157 ms:

function updateObjectValues() {
    $('.objects').html('12345678'); // ~500 DIVs
}

Passing a number is over 3x faster than a string. Why are these results so dramatically different? And, is there any way to help the performance of the string?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery