jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<script src="https://code.jquery.com/jquery-git2.min.js"></script>
<script>
// Changes XML to JSON
function xmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) { // element
// do attributes
if (xml.attributes.length > 0) {
obj["@attributes"] = {};
for (var j = 0; j < xml.attributes.length; j++) {
var attribute = xml.attributes.item(j);
obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
}
}
} else if (xml.nodeType == 3) { // text
obj = xml.nodeValue;
}
// do children
if (xml.hasChildNodes()) {
for(var i = 0; i < xml.childNodes.length; i++) {
var item = xml.childNodes.item(i);
var nodeName = item.nodeName;
if (typeof(obj[nodeName]) == "undefined") {
obj[nodeName] = xmlToJson(item);
} else {
if (typeof(obj[nodeName].length) == "undefined") {
var old = obj[nodeName];
obj[nodeName] = [];
obj[nodeName].push(old);
}
obj[nodeName].push(xmlToJson(item));
}
}
}
return obj;
};
</script>
testxml = '<svg>';
for (i = 0; i < 1000; i++) {
testxml += "<polyline id='i" + i + "'></polyline>";
}
testxml += '</svg>';
parser = new DOMParser();
xmlDoc = parser.parseFromString(testxml, "text/xml");
jsonDoc = xmlToJson(xmlDoc);
Ready to run.
Test | Ops/sec | |
---|---|---|
Traverse XML DOM |
| ready |
Traverse JSON |
| ready |
Convert XML > JSON and Traverse JSON |
| ready |
Traverse XML with different id lookup |
| ready |
Traverse XML with jQuery attribute get |
| ready |
Traverse XML with jQuery direct attribute get |
| ready |
Traverse XML without jQuery |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.