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>
var CycleDetection = {
generateCyclicObject: function (size) {
var root = {};
var obj = root;
for (var i = 0; i < size; ++i) {
obj['child'] = {};
obj = obj['child'];
}
obj['child'] = root;
return root;
},
array: function (obj) {
var seenObjects = [];
function detect (obj) {
if (typeof obj === 'object') {
if (seenObjects.indexOf(obj) !== -1) {
return false;
}
seenObjects.push(obj);
for (var key in obj) {
if (obj.hasOwnProperty(key) && !detect(obj[key])) {
return false;
}
}
}
return true;
}
return detect(obj);
},
mark: function (obj) {
var seenObjects = [];
var mark = String(Math.random());
function detect (obj) {
if (typeof obj === 'object') {
if (mark in obj) {
return false;
}
obj[mark] = true;
seenObjects.push(obj);
for (var key in obj) {
if (obj.hasOwnProperty(key) && !detect(obj[key])) {
return false;
}
}
}
return true;
}
var result = detect(obj);
for (var i = 0; i < seenObjects.length; ++i) {
delete seenObjects[i][mark];
}
return result;
},
json: function (obj) {
var isNativeJSON = typeof JSON !== 'undefined' && JSON.stringify.toString().match(/\{ \[native code\] \}$/);
if (!isNativeJSON) {
throw 'Native JSON.stringify is not available, can\'t use this technique.';
}
try {
JSON.stringify(obj);
return true;
} catch (e) {
return false;
}
}
};
var o100 = CycleDetection.generateCyclicObject(100);
var o1000 = CycleDetection.generateCyclicObject(1000);
var o10000 = CycleDetection.generateCyclicObject(10000);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
[100] Array |
| ready |
[100] Native JSON |
| ready |
[100] Mark |
| ready |
[1000] Array |
| ready |
[1000] Native JSON |
| ready |
[1000] Mark |
| ready |
[10000] Array |
| ready |
[10000] Native JSON |
| ready |
[10000] Mark |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.