jquery.cookie

JavaScript performance comparison

Revision 3 of this test case created

Info

Test performance of jquery.cookie access

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    $.cookie("TEST", 123);
    $.cookie("TEST2", 345);
    $.cookie("TEST3", 123);
    $.cookie("TEST4", 345);
    $.cookie("TEST5", 123);
    $.cookie("TEST6", 345);
   
    var getCookieValue = function(key) {
      return $.cookie(key);
    }
   
    var cookieHash = {};
    var currentCookieVal = undefined;
    var isCacheValid = function() {
      return currentCookieVal === document.cookie;
    }
    var getHashedCookieVal = function(key) {
      if (!isCacheValid()) {
        cookieHash = {
          key: $.cookie(key)
        }
      }
      if (cookieHash[key] == null) {
        cookieHash[key] = $.cookie(key);
      }
      return cookieHash[key];
    }
};

Benchmark.prototype.teardown = function() {
    $.cookie("TEST", null);
    $.cookie("TEST2", null);
    $.cookie("TEST3", null);
    $.cookie("TEST4", null);
    $.cookie("TEST5", null);
    $.cookie("TEST6", null);
   
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Accessing Cookie via $.cookie
var value = getCookieValue("TEST")
pending…
Accessing Cookie via object hash
var value = getHashedCookieVal("TEST")
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