localStorage vs. Objects

JavaScript performance comparison

Revision 10 of this test case created by Bram Stein

Info

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

Preparation code

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

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 localStorage getItem
value = localStorage.getItem('foo');
pending…
Reading from localStorage index
value = localStorage['foo'];
pending…
Reading from localStorage property
value = localStorage.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:

3 comments

James commented :

This is like testing whether it's faster to access object in memory or retrieve it from harddrive. I wonder which one is faster...

Chris commented :

wonder why IE9 crashes on this page, would be interesting too. Also some times are just weird (Android 2.1<2.2>2.3)?!

Joe Dev commented :

@James, that is exactly what it is.

Add a comment