Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs for..of String 10000
(version: 0)
Compare loop performance
Comparing performance of:
for vs for..of
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var str = 'a'.repeat(10000)
Tests:
for
for (var i = 0; i < str.length; i++) { str[i] }
for..of
for (var i of str) { i; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for
for..of
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is designed to compare the performance of two different loop constructs: `for` and `for...of`. The script preparation code creates a string variable `str` containing 10,000 characters repeated using the `'a'.repeat(10000)` method. **Options Compared** Two options are being compared: 1. **Classic `for` loop**: The first test case uses a traditional `for` loop with an index variable `i`. This is a common way to iterate over arrays or strings in JavaScript. 2. **`for...of` loop**: The second test case uses the `for...of` loop, which is a more modern and concise way to iterate over arrays or iterables. **Pros and Cons** * **Classic `for` loop**: + Pros: Widely supported across different browsers and environments. + Cons: Can be verbose and less readable for complex iterations. * **`for...of` loop**: + Pros: More concise and readable, especially for simple iterations. + Cons: May not be as widely supported in older browsers or environments. **Other Considerations** The benchmark also includes the browser, device platform, operating system, and executions per second. This provides a more comprehensive view of the performance differences between the two loop constructs. **Library Usage** Neither of the test cases uses any external libraries. The script preparation code is self-contained, and the loops are executed directly in the browser's context. **Special JavaScript Features** The `for...of` loop utilizes a special JavaScript feature called "iterators" or "iteration protocols". This allows the loop to work with arrays, strings, and other iterables without needing an explicit index variable. The classic `for` loop does not use this feature. In summary, this benchmark is designed to compare the performance of two common loop constructs in JavaScript: traditional `for` loops and more modern `for...of` loops. By using a simple iteration task and measuring executions per second, we can get an idea of which approach is faster and more efficient.
Related benchmarks:
Compare number vs compare string
large string comparison benchmark
JS String '+' same v.s. different strings
JS String '+' short v.s. long strings
JS String '+' same v.s. different strings 2
Comments
Confirm delete:
Do you really want to delete benchmark?