JavaScript performance comparison

Test case created by Dima

Preparation code

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

Benchmark.prototype.setup = function() {
  var $body = $('body'),
    $div = $('<div class="products"/>', {
      innerHTML: 'products'
    for (var i = 0; i < 1000; i++) {


Preparation code output

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
var $products = $(".products");
var $products = $("div.products");

Compare results of other browsers


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


hector commented :

I think what you a missing in this test is some noise...all your divs are the right class, so being extra specific does not gain you anything.

i would test different ratios: 100 good divs against 100 and 1000 divs with other classes.

hector commented :

your test preparation should be done in test preparation and not in setup, otherwise your second test has a larger document to work against. I replicated my tests because running the same test multiple times should give you the same result. still .products is faster.