Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Recursion vs Nested Loops
(version: 2)
Will use a function that creates steps(one side of a christmas tree)
Comparing performance of:
Nested Loops vs Recursion
Created:
one year ago
by:
Registered User
Jump to the latest result
Tests:
Nested Loops
function steps(n) { for (let row = 0; row < n; row++) { let stair = ""; for (let column = 0; column < n; column++) { if (column <= row) { stair += "#"; } else { stair += " "; } } console.log(stair); } } steps(4)
Recursion
function steps2(n, row = 0, stair = "") { if (n === row) { return; } if (n === stair.length) { console.log(stair); steps2(n, row + 1); return; } if (stair.length <= row) { stair += "#"; } else { stair += " "; } steps2(n, row, stair); } steps2(4)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Nested Loops
Recursion
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6.1 Safari/605.1.15
Browser/OS:
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Nested Loops
451004.2 Ops/sec
Recursion
182327.3 Ops/sec
Related benchmarks:
NESTEST2
NESTEST3
Big inside of small vs small inside of big loops
nested for vs non
javascript-performance-call-function-inside-for-loop
Scoping test
Scoping test without log
Scoping test without log x10
Brackets vs arrow function
Comments
Confirm delete:
Do you really want to delete benchmark?