Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
seperate getcookie vs all cookies
(version: 0)
Comparing performance of:
gc vs all
Created:
one year ago
by:
Guest
Jump to the latest result
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'];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
gc
all
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
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/OS:
Chrome 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
gc
259360.4 Ops/sec
all
155407.2 Ops/sec
Related benchmarks:
cookies vs sessionStorage
Storage Perf 2
Ga cookie grabber
JavaScript spread operator vs Object.assign performance 2001
JavaScript spread operator vs Object.assign performance 2002
seperate getcookie vs all cookies (with decode)
getCookie string vs regex
Comments
Confirm delete:
Do you really want to delete benchmark?