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>
/* Build the recursive object */
function generateRecursiveObject(n) {
var root = {};
var obj = root;
for (var i = 0; i < n; ++i) {
obj['child'] = {};
obj = obj['child'];
}
obj['child'] = root;
return root;
}
var o100 = generateRecursiveObject(100);
var o1000 = generateRecursiveObject(1000);
var o10000 = generateRecursiveObject(10000);
function CycleDetection() {
this.seenObjects = [];
}
CycleDetection.prototype = {
detect: function (obj) {
if (typeof obj === 'object') {
if ('mark' in obj) {
return false;
}
obj.mark = true;
this.seenObjects.push(obj);
for (var key in obj) {
if (obj.hasOwnProperty(key) && !this.detect(obj[key])) {
return false;
}
}
}
return true;
},
test: function (obj) {
var result = this.detect(obj);
for (var i = 0; i < this.seenObjects.length; ++i) {
delete this.seenObjects[i].mark;
}
return result;
}
}
var isNativeJSON = typeof JSON !== 'undefined' && JSON.stringify.toString().match(/\{ \[native code\] \}$/);
if (isNativeJSON) {
JSONCycleDetection = function (obj) {
try {
JSON.stringify(obj);
return true;
} catch (e) {
return false;
}
}
} else {
JSONCycleDetection = function (obj) {
throw 'Not native JSON.stringify';
}
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
[100] Javascript Cycle Detection |
| ready |
[100] Native JSON Cycle Detection |
| ready |
[1000] Javascript Cycle Detection |
| ready |
[1000] Native JSON Cycle Detection |
| ready |
[10000] Javascript Cycle Detection |
| ready |
[10000] Native JSON Cycle Detection |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.