Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Roop Performance: while vs for vs call myself
(version: 0)
Comparing performance of:
while roop vs for vs call myself
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var count = 10000; var target = []; for(let i = 0; i < count; i++) { target[i] = i; }
Tests:
while roop
var sum = 0; var i = 0; while(sum < 70000) { sum += target[i]; i++; }
for
var sum = 0; for(let i = 0; sum < 70000; i++) { sum += target[i]; }
call myself
var sum = 0; var i = 0; var sumFunction = (num) => { sum += target[num]; i++; if(sum < 70000) sumFunction(i); }; sumFunction(i);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
while roop
for
call myself
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/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
while roop
91320.3 Ops/sec
for
91455.2 Ops/sec
call myself
61779.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark defines three test cases: `while roop`, `for`, and `call myself`. These test cases compare the performance of different JavaScript loop constructs. **What is tested?** In this benchmark, the following options are compared: * **While Loop (`while roop`)**: This test case uses a traditional while loop to iterate through an array. * **For Loop (`for`)**: This test case uses a for loop with an iterator to iterate through the same array as the while loop test case. * **Call Myself (`call myself`)**: This test case uses a recursive function call to achieve the same iteration as the other two test cases. **Pros and Cons of Each Approach** 1. **While Loop (`while roop`)** * Pros: * Simple and straightforward implementation * Easy to understand for beginners * Cons: * Can be slower due to the overhead of conditional checks * May not perform well on modern JavaScript engines that optimize away unnecessary conditionals 2. **For Loop (`for`)** * Pros: * Often faster than while loops due to optimized iteration and bounds checking * Less prone to infinite loops (although this can be mitigated with proper bounds checking) * Cons: * May not work well when iterating through arrays of dynamic size * Can lead to slower performance if the iterator is expensive to compute 3. **Call Myself (`call myself`)** * Pros: * Innovative and interesting approach that highlights the potential of recursive functions in JavaScript * Cons: * Likely to be the slowest option due to the overhead of recursive function calls * May not work well for large arrays or performance-critical applications **Other Considerations** * The benchmark uses a fixed array size of 10,000 elements. In real-world scenarios, this value may vary. * The test cases iterate through an array with values ranging from 0 to the target value (70000). This range is arbitrary and might not accurately represent typical use cases. **Library Usage** None of the provided benchmark test cases explicitly uses a library. However, it's worth noting that libraries like `lodash` or `underscore` might be used in real-world applications for array iteration and manipulation. In this case, they would likely provide an additional layer of abstraction and optimization. **Special JS Features or Syntax** The test cases do not use any special JavaScript features or syntax beyond the standard language constructs mentioned earlier.
Related benchmarks:
Array fill foreach, vs for i loop
Benchmark: flatMap vs reduce vs while vs foreach
For vs Foreach copying an array
Benchmark: flatMap vs reduce vs while vs foreach vs for of
Array loop vs foreach vs map fixed by bomi
Comments
Confirm delete:
Do you really want to delete benchmark?