Parse cookies
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
encode = encodeURIComponent;
decode = decodeURIComponent;
function parse(str) {
var obj = {};
var pairs = str.split(/ *; */);
var pair;
if ('' == pairs[0]) return obj;
for (var i = 0; i < pairs.length; ++i) {
pair = pairs[i].split('=');
obj[decode(pair[0])] = decode(pair[1]);
}
return obj;
}
getAllCookies = function(str) {
var colIx, egalIx, obj, pair, prevIx;
obj = {};
prevIx = 0;
//str = decode(str);
while (true) {
colIx = str.indexOf(';', prevIx);
pair = colIx === -1 ? str.substring(prevIx).trim() : str.substring(prevIx, colIx).trim();
if (pair === '') {
return obj;
}
egalIx = pair.indexOf('=');
obj[pair.substring(0, egalIx)] = pair.substring(egalIx + 1);
if (colIx === -1) {
return obj;
}
prevIx = colIx + 1;
}
};
var testCoo = '__qca=P0-1279630214-1361530382272; gauthed=1; sgt=id=c0de28d9-13bc-4c2d-bd31-377f58a5ef52';
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
express parse |
|
pending… |
getAllCookies |
|
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:
- Revision 1: published by Simon
- Revision 2: published by 1Pupik1989
- Revision 3: published by 1Pupik1989
- Revision 4: published by Simon
0 comments