Cookie vs localStorage (v2)

Revision 2 of this benchmark created by Vuly on


Preparation HTML

<script>
  var s;
  function Cookie() {
    this.get = function(name) {
      var cookies = document.cookie.split(";");
      for (var i = 0; i < cookies.length; i++) {
        if (cookies[i].indexOf('__u') == -1 && cookies[i].indexOf('PHPSESSID') == -1) {
          var a = cookies[i].split("=");
          if (a.length == 2) {
            a[0] = a[0].replace(/^\s+|\s+$/g, '');
            a[1] = a[1].replace(/^\s+|\s+$/g, '');
            if (a[0] == name) {
              return unescape(a[1]);
            }
          }
        }
      }
      return "";
    };
    this.set = function(name, value, seconds, path, domain, secure) {
      var cookie = (name + "=" + escape(value));
      if (seconds) {
        var date = new Date(new Date().getTime() + seconds * 1000);
        cookie += ("; expires=" + date.toGMTString());
      }
      cookie += (path ? "; path=" + path : "");
      cookie += (domain ? "; domain=" + domain : "");
      cookie += (secure ? "; secure" : "");
      document.cookie = cookie;
    };
    this.del = function(name) {
      document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
    };
  }
  
  var info = '84t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg584t71gh4bp9=vg5';
  var cookie = new Cookie();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Cookie
cookie.set('info',info, 200000);
ready
localStorage
window.localStorage.setItem('info', info);
ready
get cookie
s = cookie.get('info');
ready
get localStorage
s = window.localStorage.getItem('info');
ready

Revisions

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