localStorage vs. Cookies (v19)

Revision 19 of this benchmark created by Nicholas C. Zakas on


Preparation HTML

<script>
  var value = document.cookie;

  if (value.length) {
      localStorage.setItem("foo", document.cookie);
  } else {
      value = "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef";
      localStorage.setItem("foo", value);
      document.cookie = value;
  }
  
  var value;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Reading from cookie
value = document.cookie;
ready
Reading from localStorage getItem
value = localStorage.getItem('foo');
ready
Writing to cookie
document.cookie = "bar=fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo";
ready
Writing to localStorage property
localStorage.setItem("bar", "fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
ready

Revisions

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