localStorage vs. Objects (v36)

Revision 36 of this benchmark created on


Description

Tests the difference between reading from localStorage as compared to reading data from an object.

Preparation HTML

<script src="https://code.jquery.com/jquery-git2.js"></script>

<div id="test" foo="body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }"></div>

Setup

localStorage.setItem("foo", "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }");
      
    window.FOO = {
     foo: "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }"
    };
      
    var value;

Teardown


    value = null;
    delete value;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Reading from an object
value = FOO.foo;
ready
Reading from an object2
value = FOO["foo"];
ready
Reading from 'localStorage' getItem
value = localStorage.getItem('foo');
ready
Reading from 'localStorage' index
value = localStorage['foo'];
ready
Reading from 'localStorage' property
value = localStorage.foo;
ready
Raw attribute
value = document.getElementById("test").getAttribute('foo');
ready
hybrid jQuery attribute
value = $("#test")[0].getAttribute('foo');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.