simple-get-cookie-by-name

Benchmark created on


Setup

document.cookie = "mp_67235e8e713798d5ac81930081eb3db9_mixpanel=%7B%22distinct_id%22%3A%20%22151b75c6e1f122-04d8ef673-6616167b-1fa400-151b75c6e20161%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%7D";
  document.cookie = 'platformjs={"tablet":null,"mobile":null,"version":null}';
  document.cookie = "dmz=desktop";
  document.cookie = '__gads=ID=bd58c453b06ea9eb:T=1450481035:S=ALNI_MajK_d4IKO7G4fqSCVvQZY4BrKVhg';
  document.cookie = 'oml=direct';
  document.cookie = 'optimizelyEndUserId=oeu1450481036225r0.6283963595051318';
  document.cookie = '__qca=P0-121265790-1450481037136';
  document.cookie = 'fbm_63203377906=base_domain=.ehow.com';
  document.cookie = 'GED_PLAYLIST_ACTIVITY=W3sidSI6IkZyMC8iLCJ0IjoxNDUwNDgxMTQyLCJlZCI6eyJpIjp7InciOnsidHQiOjEwNSwicGQiOjEwNSwiYnMiOjEwfX0sImEiOlt7Imt2Ijp7Im0iOjF9fSx7Imt2Ijp7Im0iOjc4fX0seyJrdiI6e319LHsia3YiOnt9fSx7Imt2Ijp7fX0seyJrdiI6e319XX0sIm52IjowLCJwbCI6MTA1fV0.';
  document.cookie = '__srret=1';
  document.cookie = '__srui=6335576d-8332-11e5-896c-22000b20094d';
  document.cookie = 'XSRF-TOKEN=746ae7c08f3c8871c0beb863f4ac71d627e28716%7Ecb1342bf50beb282cade9a75cfa10cbb88a63521';
  document.cookie = 'mp_fe3f950026c2ee2831c431be2ae65314_mixpanel=%7B%22distinct_id%22%3A%20%22151ef0d9bf6f7-0e408f607-6616167b-1aeaa0-151ef0d9bf71c9%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%7D';
  document.cookie = '_dc_gtm_UA-709906-67=1';
  document.cookie = 'optimizelySegments=%7B%22160860865%22%3A%22false%22%2C%22160960461%22%3A%22referral%22%2C%22161008231%22%3A%22none%22%2C%22161023052%22%3A%22gc%22%7D';
  document.cookie = 'optimizelyBuckets=%7B%7D';
  document.cookie = 'optimizelyPendingLogEvents=%5B%5D';
  document.cookie = '_ga=GA1.2.1973201679.1450481034';
  document.cookie = '_gat_UA-709996-67=1';
  document.cookie = 'ehnvr=1402016967138241517';
  document.cookie = 'ehnv=1452128070927775559';
  document.cookie = 'commerce_visitor_id=1495779093.87344887.1402016967';
  document.cookie = 'commerce_visit_id=2736215073.1452128070';
  
  window.getCookie = function(name) {
    var value = "; " + document.cookie;
    var parts = value.split("; " + name + "=");
    if (parts.length == 2) return parts.pop().split(";").shift();
  }
  
  window.getCookieRegex = function(name) {
    match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
    if (match) return match[2];
  }

Test runner

Ready to run.

Testing in
TestOps/sec
getcookie no regex
window.getCookie('XSRF-TOKEN')
ready
getcookie regex
window.getCookieRegex('XSRF-TOKEN')
ready

Revisions

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