Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
seperate getcookie vs all cookies (with decode)
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0
Browser:
Chrome 128
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
gc
211140.5 Ops/sec
all
145688.2 Ops/sec
Script Preparation code:
function getCookies(str) { str = str || document.cookie; var reKey = /(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g; var cookies = {}; var match; var cnt = 0; while ((match = reKey.exec(str))) { cnt += 1; reKey.lastIndex = match.index + match.length - 1; var k = match[1]; var v = decodeURIComponent(match[2]); if (!!cookies[k]) { if (typeof cookies[k] == "string") { cookies[k] = [cookies[k]]; } cookies[k].push(v); } else { cookies[k] = v; } } !!!cnt && (cookies = undefined); return cookies; } // make the multiple values of the cookie into a comma delimitted string function all(str) { str || document.cookie; let cookies = getCookies(str); if (!!cookies) { if (!!cookies["BGC_AUT_LVL"]) { if (typeof cookies["BGC_AUT_LVL"] !== "string") { cookies["BGC_AUT_LVL"] = cookies["BGC_AUT_LVL"].join(","); } } } else { cookies = {}; } return cookies; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(";"); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == " ") c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) { var d = c.substring(nameEQ.length, c.length); d = decodeRFC(d); return d; } } return undefined; } function decodeRFC(s) { s = s + ""; return s.replace(/\*/gm, "##").replace(/##/gm, ",").replace(/!/gm, " "); } document.cookie = "foo=bar+"+performance.now(); document.cookie = "hello=bar+"+performance.now(); document.cookie = "world=bar+"+performance.now(); document.cookie = "foo=bar2+"+performance.now();
Tests:
gc
var cookie1 = getCookie('foo'); var cookie1 = getCookie('hello'); var cookie1 = getCookie('world'); var cookie1 = getCookie('foo');
all
var cookies = all(); var cookie1= cookies['foo']; var cookie2= cookies['hello']; var cookie3= cookies['world']; var cookie4= cookies['foo'];