Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Reference vs Dereference with object containing array of 10 000 elements
(version: 0)
Comparing performance of:
Reference vs Dereference
Created:
7 years ago
by:
Registered User
Jump to the latest result
Tests:
Reference
const size = 10000; const obj = { arr: Array(size).fill(1) }; let res; const ref = obj.arr; for (let i = 0; i < size; i++) { res = ref[i]; }
Dereference
const size = 10000; const obj = { arr: Array(size).fill(1) }; let res; for (let i = 0; i < size; i++) { res = obj.arr[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Reference
Dereference
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0
Browser/OS:
Firefox 133 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Reference
20799.2 Ops/sec
Dereference
20342.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark test cases for you. **What is tested?** The benchmark tests two approaches to accessing elements in an array within an object: 1. **Reference**: This approach stores a reference to the `arr` property of the object in a separate variable, `ref`, and then iterates over the array using this reference. 2. **Dereference**: This approach accesses the `arr` property directly on the object (`obj`) and uses its index to access each element. **Options compared** The benchmark compares these two approaches: * **Reference**: Using a separate variable to store a reference to the array element * **Dereference**: Accessing the array element directly on the object **Pros and Cons of each approach:** 1. **Reference**: * Pros: + Might be slightly faster due to potential optimization by the JavaScript engine for accessing an array through a separate variable. + Could allow for better caching or memoization opportunities, potentially leading to performance gains. * Cons: + May introduce additional memory usage due to the extra variable. 2. **Dereference**: * Pros: + Typically more straightforward and easier to understand. + Might not introduce any significant overhead in terms of memory or execution time. * Cons: + May be slightly slower due to the need to access the array element through the object's property. **Library/JavaScript feature** There is no library used in this benchmark. However, it does utilize some JavaScript syntax features: * **let**, **const**, and **for` loops are standard JavaScript syntax. * The `Array(size).fill(1)` expression creates a new array with `size` elements, filled with the value `1`. **Other considerations** The benchmark focuses on measuring the performance difference between these two approaches. To get accurate results, it's essential to ensure that: * Both the reference and dereference implementations are identical, except for the approach being tested. * The script preparation code is minimal, avoiding any potential side effects or optimizations. * The HTML preparation code is also minimal, as its impact on performance might be negligible. **Alternative approaches** Other alternatives could include: * Using `Array.prototype.forEach()` instead of a traditional `for` loop * Employing more advanced optimization techniques, such as inlining the array access or using a specialized array-iterator * Utilizing different data structures, like a typed array or a buffer However, these alternative approaches are not explicitly tested in this benchmark.
Related benchmarks:
Dict vs. Map vs. Array
Various Array constructors vs literal performance (10_000 items)
Object key access vs array index access 10000
Object key access vs array index access 100000
Object key access vs array index access 1000000
Comments
Confirm delete:
Do you really want to delete benchmark?