Remove attr and Remove data composed vs vanilla chained

JavaScript performance comparison

Test case created by John Bender

Info

This tests the performance of a vanilla chain of both $.fn.removeAttr and $.fn.removeData against the performance of a composed version of the underlying $.removeAttr and $.removeData.

Preparation code

<script src="//code.jquery.com/jquery-1.7.2.js"></script>
<script src="https://raw.github.com/johnbender/jquery-lazy-proxy/master/lazy.js"></script>
<script>
window.testElementCount = 10;
</script>
<script src="https://raw.github.com/johnbender/jquery-lazy-proxy/master/test/proxies-perf.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    // cache the test sets
    window.testSetDivs = $( "[data-test]" );
   
    // add the attribute and data to be removed
    window.testSetDivs
      .attr("foo", "bar")
      .attr("bing", "bang")
      .data( "baz", "bak" );
};
</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
Vanilla $.fn.removeAttr and $.removeData chain
window.testSetDivs.removeAttr( "foo" ).removeData( "baz" );
pending…
Composed $.removeAttr and $.removeData with mapping using side effects
window.testSetDivs.cleanUpWithArgsElementAlter( "foo", "baz" );
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