dom query vs js tracking

JavaScript performance comparison

Test case created by Filipe Araujo

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
var html = '';

for(var i = 1000; i> 0; i--){
   if( i === 14 || i === 16) {
       html += '<div class="foo blue'+i+'"></div>';

   } else {
       html += '<div class="foo"></div>';
   }
}

$('body').append(html);

var $el = $('.foo.blue14');

</script>

<style>
.foo {
background:#fcc;
height: 10px;
margin-top: 4px;
}
.blue14, .blue16 {
background: blue;
}
</style>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
dom query
$('.foo.blue16').removeClass('blue16');
pending…
test
$el.removeClass('.blue14');
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment