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="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
window.tr = function() {
var a = arguments;
for (var i = 0; i < a.length; i++) a[i] = String(a[i]);
var s = Array.prototype.join.call(a, ' ');
var n = document.getElementById('message');
n.value += s + '\n';
}
function makeXML(N, depth, o, isRoot) {
o.i++;
var s = '<a' + depth + '>';
if (depth > 0) {
var i = N;
while (i--) s += makeXML(N, depth - 1, o);
} else {
s += 'A';
o.i++;
}
s += '</a' + depth + '>';
if (isRoot) {
var x = document.createElement('div');
x.innerHTML = s;
return x;
}
return s;
}
var o = {
i: 0
};
var x = makeXML(4, 4, o, true);
tr('Total Nodes:', o.i);
NN = o.i;
var CC = 0;
function tt1pre(x) { // 306000 op/sec
var fc;
while (x) {
CC++; //tr(x.nodeType); // x is child
if (fc = x.firstChild) tt1pre(fc);
x = x.nextSibling;
}
}
function tt1post(x) { // 338000 op/sec
var fc;
do {
CC++; //tr(x.nodeType); // x is child
if (fc = x.firstChild) tt1post(fc);
} while (x = x.nextSibling);
}
function tt2a(x) { // 215500
CC++; //tr(x.nodeType);
if (x = x.childNodes) {
var i = x.length;
while (i--) tt2a(x[i]);
}
}
function tt2b(x) { // 224000
CC++; //tr(x.nodeType);
if (x = x.childNodes) {
var i = x.length;
while (i) tt2b(x[--i]);
}
}
CC = 0;
tt1pre(x);
tr('tt1pre', CC);
CC = 0;
tt1post(x);
tr('tt1post', CC);
CC = 0;
tt2a(x);
tr('tt2a', CC);
CC = 0;
tt2b(x);
tr('tt2b', CC);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
nextSibling, pre-test |
| ready |
nextSibling, post-test |
| ready |
childNodes, post-dec i |
| ready |
childNodes, pre-dec i |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.