Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array vs int32array with 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; } tb = Array.from(ta);
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:
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 break down the provided JSON and explain what's being tested, compared, and its implications. **Benchmark Definition** The benchmark is defined by two scripts: `Script Preparation Code` and `Html Preparation Code`. The script prepares an array `a` with 10,000 random integers between 0 and 1,000,000. A typed array `ta` is created from the same data using `Int32Array`. **Comparison** The benchmark tests two approaches: 1. **Array**: The first test case compares the performance of the built-in JavaScript array (`a`). It measures the time taken to sort the array. 2. **Typed Array**: The second test case compares the performance of a typed array (`ta`) with its equivalent JavaScript array. It measures the time taken for two operations: * Incrementing elements in the typed array and converting it back to an array (`Array.from(ta)`). * Sorting the original typed array (`ta.sort()`). **Pros and Cons** 1. **Array vs Typed Array**: * **Typed Arrays**: Pros: Better performance, lower memory usage, and more precise control over data types. Cons: Not all browsers support typed arrays or `Int32Array`. * **Arrays**: Pros: Widespread browser support, easier to work with for most use cases. Cons: Potential performance issues, especially for large datasets. 2. **Incrementing elements in Typed Array**: * **Pros**: More efficient than incrementing elements in a regular array, as it avoids the need for dynamic typing. * **Cons**: Still incurs overhead due to conversion between `Int32Array` and an array. **Library: None** There are no external libraries used in this benchmark. **Special JS feature or syntax: None** No special JavaScript features or syntax are being tested in this benchmark. **Benchmark Results** The latest benchmark results show the executions per second for each test case: 1. **Typed Array Sort**: 68466.3515625 2. **Array Sort**: 212.71034240722656 3. **Typed Array I/O**: 159.46966552734375 4. **Array I/O**: 142.50230407714844 The results indicate that the typed array is significantly faster for sorting and incrementing elements, but the difference is not as pronounced for simple array operations. **Alternatives** Other alternatives to consider when working with large datasets or performance-critical code: 1. **Web Workers**: Run computationally intensive tasks in separate threads to offload work from the main thread. 2. **WebAssembly**: Compile JavaScript code into a low-level, platform-agnostic binary format for improved performance and security. 3. **Native Code Generation**: Use tools like `escodegen` or `recast` to generate native code from JavaScript, which can result in faster execution. Keep in mind that the choice of alternatives depends on the specific use case, performance requirements, and constraints.
Related benchmarks:
array vs int32array without 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?