JS - dome search

JavaScript performance comparison

Test case created by oserx

Preparation code

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

<div id="testid">
TEST ID
</div>

<div class="test">
  <div id="unu">
    TEST class>ID
  </div>
</div>
<script>
Benchmark.prototype.setup = function() {
    // Build the DOM selection query
    function $q( selector, ctx ) {
      ctx = ctx || document;
   
      // Return methods for lazy evaluation of the query
      return {
   
        // Return array of all matches
        all: function() {
          var list, ary = [];
          list = ctx.querySelectorAll( selector );
          for ( var i = 0; i < list.length; i++ ) {
            ary[ i ] = list[ i ];
          }
          return ary;
        },
   
        // Return first match
        first: function() {
          return ctx.querySelector( selector );
        },
   
        // Return last match
        last: function() {
          var list = ctx.querySelectorAll( selector );
          return list.length > 0 ? list[ list.length - 1 ] : null;
        }
   
      };
   
    }
};
</script>

Preparation code output

TEST
TEST ID
TEST class>ID

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Own JS - Class
var x=$q(".test");

 
pending…
jquery - Class
var x=$(".test");
pending…
Own - ID
var x=$q("#testid");
pending…
Jquery - ID
var x=$("#testid");
pending…
Own - ID
var x=$q(".test #unu");
pending…
Jquery - ID
var x=$(".test #unu");
pending…
Own - all divs
var x=$q("div");
pending…
Jquery - all div
var x=$("div");
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