Для такого небольшого объекта в принципе одинаково.
var start = performance.now();
for (var i = 0; i < 100000; i++)
{
function listToArray(obj) {
var rez = [];
JSON.stringify(obj).replace(/\"value\":\d+/g, function (str) { rez.push(str.split(':')[1]) });
return rez;
}
var a = { value: 5, rest: { value: 10, rest: { value: 15, rest: { value: 30, rest: null } } } };
}
alert(performance.now()-start)
var start = performance.now();
for (var i = 0; i < 100000; i++)
{
function listToArray(obj) {
return obj.rest ? [obj.value].concat(listToArray(obj.rest)) : [obj.value];
}
a = { value: 5, rest: { value: 10, rest: { value: 15, rest: { value: 30, rest: null } } } };
}
alert(performance.now()-start)