Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array vs TypedArray read performance
(version: 1)
Comparing performance of:
Array write vs TypedArray write
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
Array write
var array = new Array(100000) let x for (let i=0; i<array.length; i++) { x = array[i] }
TypedArray write
var typedArray = new Uint8Array(100000) let x for (let i=0; i<typedArray.length; i++) { x = typedArray[i] }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array write
TypedArray write
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 18 on iOS 18.5
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array write
12478.9 Ops/sec
TypedArray write
23568.1 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The provided benchmark compares the performance of reading data from two types of arrays in JavaScript: standard JavaScript arrays (`Array`) and typed arrays (`TypedArray`, specifically `Uint8Array`). ### Options Compared 1. **Array**: - **Test Case**: This benchmark reflects a performance assessment of reading from a standard array, created using `new Array(100000)`. - **Method**: It iterates through the array, accessing each element and assigning it to variable `x`. 2. **TypedArray**: - **Test Case**: This evaluates the performance of reading from a typed array created with `new Uint8Array(100000)`. - **Method**: Similar to the standard array, it iterates through the typed array and assigns each element to `x`. ### Pros and Cons #### Standard JavaScript Arrays: - **Pros**: - Flexible in terms of types: can hold items of any type (e.g., numbers, strings, objects, etc.). - More features available, such as methods for easy manipulation (e.g., `map`, `filter`, etc.). - **Cons**: - Generally slower for numeric operations and large datasets since they have additional overhead to accommodate mixed data types and dynamic resizing. - Memory usage can be less efficient as they are not optimized for specific data types. #### Typed Arrays: - **Pros**: - Optimized for performance with numeric data: designed to handle large volumes of numeric data efficiently. - Better memory performance for numeric data as they store elements in a contiguous memory block. - Provides a more predictable access speed, especially significant for performance-sensitive applications, such as graphics processing or high-performance computing. - **Cons**: - Limited to specific data types (e.g., `Uint8Array` stores unsigned 8-bit integers only). - Lacks some of the convenience features present in standard arrays (like built-in methods for manipulation). ### Other Considerations - **Performance Metrics**: The benchmark results show the number of executions per second for each type of array when reading data. - **Array**: 15,593.74 executions per second. - **TypedArray**: 15,209.17 executions per second. - While the standard array performed better in this particular test, the performance characteristics can vary depending on the use case and the specific operations being executed. - **Use Cases**: - Use standard arrays when flexibility is required and you don’t need to maximize speed for numeric calculations. - Opt for typed arrays when working with large sets of numerical data that demand high performance, especially in applications like WebGL, data processing, or when interfacing with binary data. ### Alternatives 1. **Regular JS Objects**: Used for key-value pairs but not optimal for indexed collections. 2. **Set and Map**: More suitable for unique values and key-value pairs but also not optimized for indexed access. 3. **More Complex Data Structures**: Like linked lists, trees, or other custom structures, which may be more appropriate depending on the specific needs of the application. In conclusion, the choice between a standard array and a typed array depends on the specific use case, data types involved, and performance requirements. Each has its benefits and drawbacks, making your task a matter of assessing the context in which they will be applied.
Related benchmarks:
Array vs Typed Array vs Buffer Typed Array
UInt8Array vs cast to array index access
UInt8Array vs cast to array index access 10k
Array vs TypedArray write performance
TypedArray set() vs setter performance
Array initialization: preallocate a typed array vs vanilla preallocation
Array vs TypedArray write performance %%%%%%%%%%%%
Array vs TypedArray write performance ttttttt
Array vs TypedArray write performance2
Comments
Confirm delete:
Do you really want to delete benchmark?