Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Random I/O various arrays
(version: 0)
Comparing performance of:
mixed use array vs single use array vs typed array
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var a1 = new Array(100000); var a2 = new Array(100000); var a3 = new Float64Array(100000); for (let i = 0; i < 100000; ++i) { const x = Math.random(); a1[i] = x < 0.5 ? Math.random().toString() : x; a2[i] = Math.random(); a3[i] = Math.random(); }
Tests:
mixed use array
for (let i = 0; i < 10000; ++i) { const m = (Math.random() * 10000) | 0; a1[m] = a1[m] + Math.random(); }
single use array
for (let i = 0; i < 10000; ++i) { const m = (Math.random() * 10000) | 0; a2[m] = a2[m] + Math.random(); }
typed array
for (let i = 0; i < 10000; ++i) { const m = (Math.random() * 10000) | 0; a3[m] = a3[m] + Math.random(); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
mixed use array
single use array
typed array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
mixed use array
302.8 Ops/sec
single use array
4812.1 Ops/sec
typed array
6436.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definitions and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The first part is the benchmark definition in JSON format, which represents a JavaScript microbenchmark. Here's a summary of what's being tested: * The script preparation code initializes three arrays: `a1`, `a2`, and `a3`. These arrays will be used to test different aspects of JavaScript. + `a1` is an array of strings with random values, where each value has an equal chance of being a string or an integer. + `a2` is an array of numbers with random values. + `a3` is a typed array (specifically, a Float64Array) of numbers with random values. The script preparation code also includes a loop that populates these arrays with 100,000 elements each. **Individual Test Cases** There are three test cases defined: 1. **Mixed use array**: This test case iterates over the first 10,000 elements of `a1` and updates the corresponding element in `a2`. The index is generated using `Math.random() * 10000 | 0`, which gives a random integer between 0 and 9,999. * Pros: Simple to understand and implement, allows for easy testing of array manipulation techniques. * Cons: May not accurately represent real-world scenarios where arrays are frequently updated or modified. 2. **Single use array**: This test case is similar to the mixed use array test case, but it updates the corresponding element in `a3` instead of `a2`. The only difference is that the index generated using `Math.random() * 10000 | 0` is now used for both arrays. * Pros: Similar pros and cons as the mixed use array test case, with an additional consideration that the typed array may have performance advantages due to its memory management capabilities. 3. **Typed array**: This test case iterates over the first 10,000 elements of `a3` (the Float64Array) and updates the corresponding element in `a1`. The index is generated using `Math.random() * 10000 | 0`, just like in the mixed use array test case. * Pros: Allows for testing of performance aspects related to typed arrays, which can provide better memory management and faster access to elements compared to regular arrays. * Cons: May require more complex implementation details due to the specifics of Float64Array operations. **Library** There is no explicit library mentioned in the benchmark definition or test cases. However, it's worth noting that the `Float64Array` type is a built-in JavaScript type introduced in ECMAScript 2015 (ES6). **Special JS Feature/Syntax** None of the test cases explicitly use any special JavaScript features or syntax beyond standard array manipulation and iteration techniques. **Other Alternatives** To measure performance differences between these tests, other alternatives could be explored: * Using different array sizes or data distribution to simulate real-world scenarios. * Adding more complex operations, such as sorting, filtering, or merging arrays, to the test cases. * Using specialized libraries like `Benchmark` or `micro-benchmark` for more accurate and controlled performance measurements. * Running tests on different browsers, devices, or environments to explore platform-specific optimizations. Keep in mind that the primary goal of this benchmark is to compare the performance differences between using regular arrays versus typed arrays.
Related benchmarks:
array vs Float64Array write performance
array vs float32array without conversion 3
array vs float64 for io and slice
array vs float64 for io and slice (fixed)
Comments
Confirm delete:
Do you really want to delete benchmark?