Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
iterative vs recursion
(version: 2)
Comparing performance of:
recursion vs iterative
Created:
one year ago
by:
Registered User
Jump to the latest result
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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
recursion
iterative
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
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/OS:
Chrome 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
recursion
62710.5 Ops/sec
iterative
83154.1 Ops/sec
Related benchmarks:
Lodash Flatten v.s. concat
reduce variants
maping
foomsdffdsaadfsdfas
lodash flatten+ map vs reduce
My reduce vs flatMap benchmark for collection
for of vs flatmap vs reduce 2
.map().includes() vs .some()
{} vs Map Creation
Comments
Confirm delete:
Do you really want to delete benchmark?