js objects vs data

JavaScript performance comparison

Test case created by Josh Vermaire

Info

Testing html object attributes vs data attributes

Preparation code

<div id='div'></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    $div = $('#div')
    div = document.getElementById('div')
    div.get = {one: 'test', two: 'testing'}
    div.dataset.get = {one: 'test', two: 'testing'}
    $div.data('jQGet', {one: 'test', two: 'testing'})
};
</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
html object attr set
div.set = {one: 'test', two: 'testing'}
pending…
html object attr setAttribute
div.setAttribute('set', {one: 'test', two: 'testing'})
pending…
html object attr get
div.get
pending…
html object getAttr get
div.getAttribute('get')
pending…
jquery data get
$div.data('jQGet')
pending…
jquery data set
$div.data('jQset', {one: 'test', two: 'testing'})
pending…
html data set
div.dataset.set = {one: 'test', two: 'testing'}
pending…
html data set
div.dataset.get
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