localStorage vs. Cookies

JavaScript performance comparison

Revision 27 of this test case created

Info

Tests the difference between operations with localStorage as compared to cookies.

Preparation code

<script>
  var value = document.cookie;

  if (value.length) {
      localStorage.setItem("foo", document.cookie);
  } else {
      value = "harsh";
      localStorage.setItem("foo", value);
      document.cookie = value;
  }
 
  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 cookie
value = document.cookie;
pending…
Reading from localStorage getItem
value = localStorage.getItem('foo');
pending…
Writing to cookie
document.cookie = "bar=fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo";
pending…
Writing to localStorage property
localStorage.setItem("bar", "fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
pending…
Writing to localStorage thru cookies
localStorage.setItem("foo", document.cookie);
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