localStorage vs. Objects

JavaScript performance comparison

Revision 36 of this test case created

Info

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

Preparation code

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

<div id="test" foo="body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }"></div>
<script>
Benchmark.prototype.setup = function() {
    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;
};

Benchmark.prototype.teardown = function() {
    value = null;
    delete value;
};
</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
Reading from an object
value = FOO.foo;
pending…
Reading from an object2
value = FOO["foo"];
pending…
Reading from 'localStorage' getItem
value = localStorage.getItem('foo');
pending…
Reading from 'localStorage' index
value = localStorage['foo'];
pending…
Reading from 'localStorage' property
value = localStorage.foo;
pending…
Raw attribute
value = document.getElementById("test").getAttribute('foo');
pending…
hybrid jQuery attribute
value = $("#test")[0].getAttribute('foo');
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