string spit

Benchmark created on


Setup

const cookieString = 'ucSearchParams=%7B%7D; testUserId=_7f1c6c43-7763-424c-8530-08af1564b41c; optimizelyEndUserId=_7f1c6c43-7763-424c-8530-08af1564b41c; channel-tracking=%7B%22utm_id%22%3Anull%2C%22utm_source%22%3Anull%2C%22partner%22%3Anull%2C%22referrer%22%3A%22%22%2C%22timestamp%22%3A1707139111643%7D; anon={"id":"Rpvg1lw3ENvQKmIotc0rVc-LW8wfuYZucDv14S9HLFn4s","nonce":"8d6f2b0ce11fe98601d931968be8c9e2_92304855bcd809ed304d0525e68f10e90bf4fe722756cd06fe478fe6be045e4ca76ea01df2df682cec2f37a1b6c15673","anonKey":"7AeLhPS4Ab7fztoMV…4AYOqR7%22%7D; _gid=GA1.2.2109595769.1707139035; _li_dcdm_c=.vistaprint.com; _pin_unauth=dWlkPVpXRXdNV1poTVRjdFlqQTRZeTAwTVdVeUxXSXdPV010TURrMFltUmhNREkyT0dSbA; QuantumMetricSessionID=5365a14f7a56f6c5e92d124ddd1a9251; expCtxTTL=1; ajs_anonymous_id=Rpvg1lw3ENvQKmIotc0rVc-LW8wfuYZucDv14S9HLFn4s; _scid_r=f3039a7a-41dc-42fa-9ab7-5e0d649b0d50; _rdt_uuid=1706029125406.05bdcbcf-37f4-4c95-927f-2d3469fac99f; _uetsid=e04d8010c42811eeb9cec9bffa782d3a; _uetvid=abf5c300ba1011ee9c6c6b64e51189fd; _dc_gtm_UA-68038280-26=1'

Test runner

Ready to run.

Testing in
TestOps/sec
parse every time
const getCookie = () => {
let result = null;
const cookies = cookieString.split(";");
  cookies.forEach((cookie) => {
        const cookiePair = cookie.split("=", 2);
        const cookieName = cookiePair[0].trim();
        if (cookieName === name) {
          const cookieVal = cookiePair[1];
          result = cookieVal;
        }
      });
   return result;
}

getCookie("optimizelyEndUserId");
getCookie("testUserId");
getCookie("expCtxTTL");
ready
parse into dict
const getCookie = () => cookieString.split(";")
	.map(c => c.split('='))
	.reduce((accu, current) => {
		accu[current[0].trim()] = current[1].trim();
		return accu;
	}, {});
const dict = getCookie();
dict.optimizelyEndUserId;
dict.testUserId;
dict.expCtxTTL;
ready

Revisions

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