Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array vs float32array 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 Float32Array(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; } let 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:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array sort
2474.2 Ops/sec
typedArray sort
29464.7 Ops/sec
array i/o
64207.5 Ops/sec
typedArray i/o
6391.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested in each benchmark. **Benchmark Definition** The first part of the JSON represents a benchmark definition, which outlines the specific test case: ```json { "Name": "array vs float32array without conversion", "Description": null, "Script Preparation Code": "function getRandomInt(max) {\r\n return Math.floor(Math.random() * Math.floor(max));\r\n}\r\nvar a = [...Array(10000)].map(_ => Math.random(1000000));\r\nvar ta = (new Float32Array(10000)).map(_ => Math.random(1000000));", "Html Preparation Code": null } ``` This benchmark tests the performance of two arrays: `a` and `ta`. The script preparation code initializes these arrays with 10,000 elements each, generated randomly. Note that there's no explicit conversion between `a` and `ta`, which is a key aspect of this test. **Individual Test Cases** The second part of the JSON represents multiple individual test cases: ```json [ { "Benchmark Definition": "a.sort();", "Test Name": "array sort" }, { "Benchmark Definition": "ta.sort();", "Test Name": "typedArray sort" }, { "Benchmark Definition": "for (let i = 0; i < 10000; ++i) {\r\n a[i] = a[i] + 1;\r\n}", "Test Name": "array i/o" }, { "Benchmark Definition": "for (let i = 0; i < 10000; ++i) {\r\n ta[i] = ta[i] + 1;\r\n}\r\nlet tb = Array.from(ta);", "Test Name": "typedArray i/o" } ] ``` These test cases compare the performance of different operations on arrays: * `array sort`: Sorting an array in ascending order. * `typedArray sort`: Sorting a typed array (`Float32Array` in this case) in ascending order. * `array i/o`: Incrementing each element in the array by 1 and then reading back the modified elements. * `typedArray i/o`: Performing the same operation as above, but using a typed array. **Library:** The `getRandomInt(max)` function is not a built-in library; it's a custom function created to generate random integers. However, `Float32Array` is a part of the JavaScript standard library, which represents an array of 32-bit floating-point numbers. It's used in this benchmark to test typed arrays. **Special JS Feature or Syntax:** None are explicitly mentioned, but note that some JavaScript versions may have specific optimizations or behaviors for certain array operations. However, these are not explicitly highlighted as special features or syntax in the provided JSON. **Other Considerations:** The benchmarks focus on the performance differences between arrays and typed arrays without explicit conversions. This highlights the importance of optimized data structures and efficient memory management in JavaScript applications. **Alternatives:** If you were to rewrite this benchmark, consider alternative test cases or variations: * Test the impact of different array sizes. * Explore the performance of other array operations (e.g., `reduce()`, `every()`). * Compare the performance of other typed arrays (e.g., `Int32Array`, `Uint16Array`). These alternatives could provide a more comprehensive understanding of JavaScript's performance characteristics for different data structures and operations.
Related benchmarks:
array vs float32array without conversion 2
array vs float32array without conversion 3
array vs float64 for io and slice
array vs float32array max
Comments
Confirm delete:
Do you really want to delete benchmark?