jQuery#9649

JavaScript performance comparison

Test case created by orkel

Preparation code

<div id="tester"></div>
<script>
elem = document.getElementById("tester");
   
set9469 = function( elem, value, name ) {
    // Set the existing or create a new attribute node
    var ret = elem.getAttributeNode( name );
    if ( !ret ) {
            ret = elem.ownerDocument.createAttribute( name );
            elem.setAttributeNode( ret );
    }

    ret.value = value += "";

    // #9646
    if ( name !== "value" && value !== elem.getAttribute( name ) ) {
            elem.setAttribute( name, value );
    }

    return value;
}
set = function( elem, value, name ) {
    // Set the existing or create a new attribute node
    var ret = elem.getAttributeNode( name );
    if ( !ret ) {
            ret = elem.ownerDocument.createAttribute( name );
            elem.setAttributeNode( ret );
    }
    return ( ret.value = value + "" );
}
 
</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
set
set( elem, "test", "id" );
pending…
set9469
set9469( elem, "test", "id" );
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