Jquery.data() window or document container

JavaScript performance comparison

Test case created by Skelly

Info

Compares use of JQuery $.data() when storing data in window vs document vs cached element.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
$('#foobar').data('foodata','bar - 123');
$(window).data('windata','bar - 123');
$(document).data('docdata','bar - 123');
</script>
<div id="foobar"></div>
 

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
window .data()
$('div#foobar').html($(window).data('windata'));

 
pending…
document data()
$('div#foobar').html($(document).data('docdata'));

 
pending…
div element data() - $this
$('div#foobar').html($(this).data('foodata'));
pending…
div element data()
$('div#foobar').html($('div#foobar').data('foodata'))
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