Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array vs int32array without conversion
(version: 0)
Comparing performance of:
array sort vs typedArray sort vs array i/o vs typedArray i/o
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var a = [...Array(10000)].map(_ => Math.random(1000000)); var ta = (new Int32Array(10000)).map(_ => Math.random(1000000));
Tests:
array sort
a.sort();
typedArray sort
ta.sort();
array i/o
for (let i = 0; i < 10000; ++i) { a[i] = a[i] + 1; }
typedArray i/o
for (let i = 0; i < 10000; ++i) { ta[i] = ta[i] + 1; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
array sort
typedArray sort
array i/o
typedArray i/o
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 141 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array sort
856.4 Ops/sec
typedArray sort
51682.4 Ops/sec
array i/o
20704.8 Ops/sec
typedArray i/o
17715.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The test cases are designed to compare the performance of JavaScript arrays (`a`) with `Int32Array` objects (`ta`). The tests measure execution times for various operations: sorting and iteration over the arrays. **Benchmark Definition JSON** The provided benchmark definition JSON has two main sections: 1. **Script Preparation Code**: This code generates an array `a` with 10,000 random integers between 0 and 1000000, using the `Math.random()` function. It also creates a `ta` object by mapping over an empty `Int32Array` of the same length. 2. **Html Preparation Code**: There is no HTML preparation code provided. **Individual Test Cases** There are four test cases: 1. **array sort**: Measures the execution time of sorting the array `a`. * JavaScript arrays implement a variety of sorting algorithms, including quicksort and mergesort. * Performance can vary depending on the specific implementation used by the browser. 2. **typedArray sort**: Measures the execution time of sorting the `ta` object. * `Int32Array` objects provide optimized memory layout and caching for performance-critical operations like sorting. 3. **array i/o**: Measures the execution time of iterating over the array `a` with an incrementing index. 4. **typedArray i/o**: Measures the execution time of iterating over the `ta` object. **Comparison** The tests compare the execution times of JavaScript arrays and `Int32Array` objects for different operations: * Sorting: `Int32Array` objects are expected to be faster due to their optimized memory layout. * Iteration: Both array types should perform similarly, as iteration is not a performance-critical operation. **Pros and Cons** Pros of using `Int32Array` objects: * Better performance for certain operations (e.g., sorting). * Reduced memory overhead compared to JavaScript arrays. Cons: * Limited functionality due to their type-specific nature. * May require more careful management when working with primitive types. Pros of using JavaScript arrays: * Flexibility and versatility, as they support various data types and operations. * Easier to work with for most use cases. Cons: * Typically slower than `Int32Array` objects for certain performance-critical operations (e.g., sorting). **Other Considerations** When working with `Int32Array` objects, keep in mind the following considerations: * Use primitive types when possible to avoid unnecessary conversions. * Be mindful of caching and memory layout implications. **Alternatives** If you're looking for alternatives to measure performance or explore different data structures, consider the following options: * Other data structure libraries (e.g., `Map`, `Set`) that may offer better performance for specific use cases. * Native code benchmarks using languages like C++ or Rust, which can provide more precise measurements and insights into memory allocation, caching, and parallelism. By understanding the specifics of this benchmark, you can make informed decisions about when to use JavaScript arrays versus `Int32Array` objects based on your performance requirements.
Related benchmarks:
array vs int32array with conversion
array vs float32array without conversion
array vs float32array without conversion 2
array vs float32array max
Comments
Confirm delete:
Do you really want to delete benchmark?