test

JavaScript performance comparison

Revision 11 of this test case created

Preparation code

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

<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<script>
Benchmark.prototype.setup = function() {
    var o = {1:1, 2:2};
    var n = 0;
    var s = 'string';
   
   
    function is(element){
    return element && element.nodeType;
    }
   
   
    function get(selector, selectorParent){
                selectorParent = undefined === selectorParent ? document : get(selectorParent);
                return is(selector) ? selector : selectorParent.querySelector(selector);
        };
   
    function getAll(selector, selectorParent){
                selectorParent = undefined === selectorParent ? document : this.get(selectorParent);
               
                if(is(selector)){
                        return [selector];
                }
               
                var array = [],
                        i = 0,
                        nodeList = selectorParent.querySelectorAll(selector)
                ;
               
                for(; i < nodeList.length; i++){
                        array.push(nodeList[i]);
                }
               
                return array;
        };
};
</script>

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
1
$('div').get();
pending…
2
getAll('div');
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment