Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
cache variabled
(version: 4)
Comparing performance of:
for vs for..of vs for+cache vs for+cache+cache vs for+cache+cache+cache vs for..of+cache vs foreach + cache+ arrow vs foreach + cache+ func vs foreach
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var arr = [{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0},{name: 'test', age: 12234, sex: 1},{name: '34423', age: 1324232, sex: 0},{name: '4234', age: 134, sex: 0},{name: '3244', age: 12, sex: 1},{name: '34324', age: 4321, sex: 0}]
Tests:
for
let buf = ''; for(let i=0; i<arr.length; i++){ buf+=arr[i].name+'/'+arr[i].sex+'-'+arr[i].age; }
for..of
let buf = ''; for(const v of arr){ buf+=v.name+'/'+v.sex+'-'+v.age; }
for+cache
let buf = ''; for(let i=0, len=arr.length; i<arr.length; i++){ buf+=arr[i].name+'/'+arr[i].sex+'-'+arr[i].age; }
for+cache+cache
let buf = ''; for(let i=0, len=arr.length; i<arr.length; i++){ const item = arr[i]; buf+=item.name+'/'+item.sex+'-'+item.age; }
for+cache+cache+cache
let buf = '', arra = arr; for(let i=0, len=arra.length; i<arra.length; i++){ const item = arra[i]; buf+=arra[i].name+'/'+arra[i].sex+'-'+arra[i].age; }
for..of+cache
let buf = '', arra = arr; for(const v of arra){ buf+=v.name+'/'+v.sex+'-'+v.age; }
foreach + cache+ arrow
let arrs = arr; let buf=''; arrs.forEach((v)=> { buf+=v.name+'/'+v.sex+'-'+v.age;})
foreach + cache+ func
let arrs = arr; let buf=''; arrs.forEach(function(v){ buf+=v.name+'/'+v.sex+'-'+v.age;})
foreach
let buf=''; arr.forEach(function(v){ buf+=v.name+'/'+v.sex+'-'+v.age;})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (9)
Previous results
Fork
Test case name
Result
for
for..of
for+cache
for+cache+cache
for+cache+cache+cache
for..of+cache
foreach + cache+ arrow
foreach + cache+ func
foreach
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 dive into the benchmark results. It appears that we have multiple tests with different variations, and their performance is being measured. Here are some observations: 1. **`foreach` vs `for` loops**: The test with only `foreach` loop (`"Test Name": "foreach "``) has a lower execution rate (281866.65625) compared to the other tests that use both `foreach` and other variations (e.g., `"Test Name": "for+cache+cache"`). This might indicate that the `foreach` loop is more efficient when used alone. 2. **`foreach` with caching**: The test with `foreach` loop and caching (`"Test Name": "foreach + cache+ arrow"`), which was introduced in a previous benchmark, seems to have a better performance (278367.5) than the original `foreach` test. This might suggest that caching can improve performance for certain use cases. 3. **`for..of` loop**: The test with only `for..of` loop (`"Test Name": "for..of"``) has a relatively low execution rate (275717.8125). It's not the lowest, but it's still decent. 4. **`for` loop with caching**: The test with only `for` loop and caching (`"Test Name": "for+cache"`), which is similar to the original benchmark, has a slightly higher performance than the previous version (30456.044921875). 5. **Other variations**: Some tests have multiple variations, such as adding or removing certain words from the `foreach` loops, but their performance is not significantly different. Overall, these results might suggest that: * The `foreach` loop can be more efficient when used alone. * Caching can improve performance for certain use cases, like the `foreach + cache+ arrow` test. * The `for..of` loop is relatively less efficient compared to other variations. * Adding caching to a `for` loop can have a positive effect. However, it's essential to note that these are benchmark results and might not be representative of real-world performance.
Related benchmarks:
lodash_array_objects
lodash_array_objects_2
Test-BC
objvsarrayfr
Comments
Confirm delete:
Do you really want to delete benchmark?