Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Direct Array vs Typed Array vs Array read performances
(version: 0)
Comparing performance of:
new TypedArray vs new Array vs Direct Array
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
new TypedArray
let arr = new Float32Array(1000000); arr[0] = Math.random(); var sum = 0; for (let i = 0; i < 1000000; i++) { sum+= arr[i]; }
new Array
let arr = new Array(1000000); arr[0] = Math.random(); var sum = 0; for (let i = 0; i < 1000000; i++) { sum+= arr[i]; }
Direct Array
let arr = []; arr[0] = Math.random(); var sum = 0; for (let i = 0; i < 1000000; i++) { sum+= arr[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
new TypedArray
new Array
Direct Array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Browser/OS:
Firefox 148 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new TypedArray
489.4 Ops/sec
new Array
181.9 Ops/sec
Direct Array
185.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases to understand what is being tested. **Benchmark Overview** The benchmark compares the performance of three different approaches for iterating over an array: 1. **Direct Array**: Using a regular JavaScript `Array` object. 2. **Typed Array**: Using a `Float32Array`, which is a typed array that stores 32-bit floating-point numbers. 3. **New Array (with explicit type)**: Creating a new `Array` object and explicitly setting its type to `Float32Array`. **Test Cases** Each test case consists of a benchmark definition, which is a JavaScript code snippet that performs the following steps: 1. Creates an array with 1 million elements. 2. Sets the first element of the array to a random value using `Math.random()`. 3. Initializes a variable `sum` to zero. 4. Iterates over the array using a `for` loop, adding each element to `sum`. The test case names are: * "new TypedArray" * "new Array" * "Direct Array" **What is being tested?** The benchmark tests the performance of these three approaches when iterating over an array. The test cases measure the number of executions per second (ExecutionsPerSecond) for each approach. **Options compared** The benchmark compares: 1. **Typed Arrays**: Using `Float32Array` to store 32-bit floating-point numbers. 2. **Explicit type**: Creating a new `Array` object and explicitly setting its type to `Float32Array`. 3. **Regular Array**: Using a regular JavaScript `Array` object. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: 1. **Typed Arrays (Float32Array)**: * Pros: Typically faster than regular arrays, as it stores data in a contiguous block. * Cons: May require more memory bandwidth due to the need to access individual elements using indices. 2. **Explicit type (new Array with Float32Array type)**: * Pros: Similar performance to typed arrays, but may be easier to manage and maintain. * Cons: May not provide the same level of optimization as true typed arrays. 3. **Regular Array**: * Pros: Wide support and compatibility across browsers and environments. * Cons: Typically slower than typed arrays or explicit type approaches. **Library and purpose** In this benchmark, there is no specific library mentioned. However, `Float32Array` is a part of the Web API, which provides access to typed arrays for efficient numerical computations. **Special JS feature or syntax** There are no special JavaScript features or syntax used in this benchmark. The code snippets are straightforward and focus on comparing different array approaches. **Other alternatives** For this type of benchmark, alternative approaches might include: 1. **Buffer**: Using the `Uint8Array` buffer API to store data in a contiguous block. 2. **WebAssembly**: Using WebAssembly modules to perform numerical computations efficiently. 3. **Native libraries**: Using native libraries like BLAS or LAPACK for optimized linear algebra operations. Keep in mind that these alternatives might not be directly applicable to this specific benchmark, but they demonstrate other ways to optimize numerical computations in JavaScript.
Related benchmarks:
Maping BooleanArray vs uInt8 Array2 vs uint8 with bitMasking _2
Maping numeric vs f32 vs f64
Extending ArrayBufferView
Extending ArrayBufferView with Properties
Maping numeric vs f32 vs f64 with add
Comments
Confirm delete:
Do you really want to delete benchmark?