caching data fetches

JavaScript performance comparison

Test case created by Josh Gruber

Info

see if there's any caching going on

Preparation code

<div id="target" data-item-one="one" data-item-two="two" data-item-three="three">hello</div>
<script>
Benchmark.prototype.setup = function() {
    var output,
      $cachedTarget = $('#id');
};
</script>

Preparation code output

hello

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
using cached target thrice
output = $cachedTarget.data('itemOne);
output = $cachedTarget.data('

  itemTwo);
output = $cachedTarget.data('itemThree);
pending…
using object thrice
output = $('#id').data('itemOne');
output = $('#id').data('itemTwo');
output = $('#id').data('itemThree');
pending…
using object once
output = $('#id').data('itemOne');
pending…
using cached once
output = $cachedTarget.data('itemOne');
pending…
using jQuery thrice
output = $.data('#id', 'itemOne');
output = $.data('#id', 'itemTwo');
output = $.data('#id', 'itemThree');
pending…
using jQuery once
output = $.data('#id', 'itemOne');
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