Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test for of loop
(version: 0)
Comparing performance of:
test1 vs test2
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
test1
const project_list = []; const DD_projects = Array.from(Array(10000000).keys()); for (let item of DD_projects) { project_list.push({ text: item, value: item, languages: item, prefix: item, }) }
test2
const project_list = []; const DD_projects = Array.from(Array(10000000).keys()); DD_projects.forEach((item)=>( project_list.push({ text: item, value: item, languages: item, prefix: item, }) ))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
test1
test2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
test1
1.4 Ops/sec
test2
1.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Definition** The benchmark definition is a JavaScript script that creates an array of 10 million items, each with four properties: `text`, `value`, `languages`, and `prefix`. The script uses two different methods to push these objects into the `project_list` array: 1. **For-of loop**: This method iterates over the `DD_projects` array using a for-of loop, where each iteration creates an object with the specified properties and pushes it into the `project_list`. 2. **forEach() method**: This method uses the `Array.prototype.forEach()` method to iterate over the `DD_projects` array, where each iteration also creates an object with the specified properties and pushes it into the `project_list`. **Options being compared** The two methods being compared are: 1. For-of loop 2. forEach() method These methods have different pros and cons: * **For-of loop**: + Pros: Can be more efficient since it avoids the overhead of function calls associated with forEach(). + Cons: May not work as expected for arrays created dynamically, as it's designed to iterate over existing elements. * **forEach() method**: + Pros: Works well with arrays created dynamically and is widely supported across browsers. + Cons: May be slower due to the overhead of function calls. **Other considerations** There are other factors that might affect performance: * Array size: With 10 million items, memory allocation and garbage collection become significant concerns. The browser's garbage collector will likely have a hard time keeping track of all the objects. * Browser optimizations: Modern browsers often implement various optimizations for array operations, such as loop unrolling or caching frequently accessed elements. **Library usage** There is no explicit library usage in these benchmark definitions. **Special JS features/syntax** None of these benchmarks use any special JavaScript features or syntax that would affect performance. They are straightforward implementations of basic iteration techniques. **Other alternatives** If you wanted to compare other iteration methods, some alternatives could be: * **Array.prototype.map()**: This method creates a new array by applying a provided function to each element of the original array. * **Array.prototype.reduce()**: This method applies a provided function to each element in an array, accumulating a result. These methods might offer different performance characteristics compared to for-of loops and forEach().
Related benchmarks:
forEach vs for loop
forEach vs optimized for loop
find() vs for...of vs for-loop more data
find() vs for...of vs for-loop moooore data
var vs let vs const loopy
Comments
Confirm delete:
Do you really want to delete benchmark?