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
Recursive vs Iterative
function clone_recursive(object) {
var result = {};
for (var key in object) {
var value = object[key];
if (typeof value === 'object') {
result[key] = clone_recursive(value);
} else {
result[key] = value;
}
}
return result;
}
function clone_iterative(object) {
var result = {};
var queue = [{base: result, value: object}];
var item;
while (item = queue.shift()) {
var current = item.value;
var base = item.base;
for (var key in current) {
var value = current[key];
if (typeof value === 'object') {
var resultValue = base[key] = {};
queue.push({base: resultValue, value: value});
} else {
base[key] = value;
}
}
}
return result;
}
function clone_iterative_linked_list(object) {
var result = {};
var queueHead = {base: result, value: object, next: null};
var queueTail = queueHead;
for(;queueHead; queueHead = queueHead.next){
var item = queueHead;
var current = item.value;
var base = item.base;
for (var key in current) {
var value = current[key];
if (typeof value === 'object') {
var resultValue = base[key] = {};
queueTail.next = {base: resultValue, value: value, next:null};
queueTail = queueTail.next;
} else {
base[key] = value;
}
}
}
return result;
}
function makeDeepObject() {
var root = {};
var current = root;
for (var i = 33, max = 136; i < max; i++) {
var key = String.fromCharCode(i);
var newObject = {};
for (var j = 0; j < 25; j++) {
newObject['a' + j] = {x: 1};
}
current[key] = newObject;
for (; j < 50; j++) {
newObject['z' + j] = {y: 2};
}
current = newObject;
}
return root;
}
var mock = makeDeepObject();
Ready to run.
Test | Ops/sec | |
---|---|---|
Recursive |
| ready |
Iterative |
| ready |
linked list |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.