closestEnabledButton

JavaScript performance comparison

Test case created by hpbuniat

Info

Changed class-comparison of the closestEnabledButton-method to indexOf.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="ui-btn test">
<div class="ui-list test2 test3">
<div>
<div class="test ui-test test2 test3">
<div>
<div class="test ui-test ui-disabled test2 test3">
<div>
<div class="ui-disabled test2 test3">
<div id="test"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
Benchmark.prototype.setup = function() {
    element=$('#test').eq(0)[0];
};
</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
old
while ( element ) {
       cname = ( typeof element.className === 'string' ) && element.className.split(' ');

        if ( cname && $.inArray( "ui-btn", cname ) > -1 && $.inArray( "ui-disabled", cname ) < 0 ) {
         break;
        }
element = element.parentNode;
}



 
pending…
new
while ( element ) {
        cname = ( typeof element.className === 'string' ) && (element.className + ' ');
        if ( cname && cname.indexOf("ui-btn ") > -1 && cname.indexOf("ui-disabled ") < 0 ) {
            break;
        }
element = element.parentNode;
}
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