Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
iterative vs recursion
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser:
Chrome 133
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
recursion
62710.5 Ops/sec
iterative
83154.1 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var myTasks = []; myCopy = null;
Tests:
recursion
function flattenTasks(tasks, flattenContacts = false){ let flattened = []; tasks.forEach(task => { if (flattenContacts) { flattened.push( { ...task, 'contacts': task?.contacts?.length ? task.contacts.map(c => c.id) : [], 'subtasks': task?.subtasks?.length ? task.subtasks.map(s => s.id_uuid) : [], } ) } else { flattened.push( { ...task, 'subtasks': task?.subtasks?.length ? task.subtasks.map(s => s.id_uuid) : [], } ) } if (task?.subtasks?.length) { flattened = [...flattened, ...flattenTasks(task.subtasks, flattenContacts)]; } }) return flattened; } myCopy = flattenTasks(myTasks);
iterative
function flattenTasks(tasks) { const result = []; const stack = [...tasks]; while (stack.length) { const task = stack.pop(); result.push({ ...task }); if (task.subtasks) { stack.push(...task.subtasks); } } return result; } myCopy = flattenTasks(myTasks);