localStorage vs. Cookies (v27)

Revision 27 of this benchmark created on


Description

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

Preparation HTML

<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

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
Writing to localStorage thru cookies
localStorage.setItem("foo", document.cookie);
ready

Revisions

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