Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set vs subarray-set vs pre-allocated subarray-set
(version: 0)
Comparing performance of:
set vs subarray-set vs pre-allocated subarray-set
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var start = 3e6; var end = 4e6; // for set var array1 = Float32Array.from({length: 1e6}, Math.random); var array2 = Float32Array.from({length: 1e6}, Math.random); // for subarray-set var array3 = Float32Array.from({length: 1e6}, Math.random); var array4 = Float32Array.from({length: 10e6}, Math.random); // for pre-allocated subarray-set var array5 = Float32Array.from({length: 1e6}, Math.random); var array6 = Float32Array.from({length: 10e6}, Math.random); var subarray6 = array6.subarray(start, end);
Tests:
set
array1.set(array2, 0);
subarray-set
array3.set(array4.subarray(start, end), 0);
pre-allocated subarray-set
array5.set(subarray6, 0);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
set
subarray-set
pre-allocated subarray-set
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 benchmark definition to understand what is being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark compares three ways of setting values in a Float32Array: 1. `set()`: Directly sets the value at a specific index in the array. 2. `subarray-set()`: Sets the value at an index within a subset of the original array, which is pre-allocated to a certain length (e.g., 10^6 elements). 3. `pre-allocated subarray-set`: Similar to the previous one, but the entire pre-allocated array is used as the subset. **Options Compared** The options are compared in terms of performance, specifically: * **set()**: Directly sets the value at a specific index in the original array. + Pros: Simple and straightforward. No extra memory allocation or copying required. + Cons: May lead to garbage collection issues if the array is too large, as it can cause significant overhead. * **subarray-set()**: Sets the value at an index within a pre-allocated subset of the original array. + Pros: Reduces garbage collection issues by using less memory. Can also reduce copying and allocation overhead. + Cons: Requires extra memory allocation for the pre-allocated array, which may lead to higher memory usage. * **pre-allocated subarray-set**: Similar to the previous one but with an even larger pre-allocated array (10^6 elements). + Pros: May provide better performance by reducing garbage collection issues and copying overhead. + Cons: Requires significantly more memory allocation and may lead to slower start-up times due to increased memory usage. **Library** No specific library is mentioned in the benchmark definition, but it's likely that Float32Array is used as the underlying data structure. Float32Array is a typed array in JavaScript that represents an array of 32-bit floating-point numbers. **Special JS Feature/Syntax** There doesn't seem to be any special JS feature or syntax used in this benchmark. The benchmark focuses on comparing different approaches to setting values in a Float32Array. **Other Alternatives** In the past, developers might have used other approaches, such as: * Using `array.prototype.fill()` instead of `set()`. While not directly comparable, it's worth noting that `fill()` can be slower than `set()` due to its overhead. * Using `array.prototype.splice()` with an empty array and then assigning the value using `push()`. This approach is likely to be slower than both `set()` and `subarray-set()` due to the unnecessary operations involved. Keep in mind that this benchmark is focused on comparing three specific approaches, and it's essential to test different scenarios and variations to ensure a comprehensive understanding of performance characteristics.
Related benchmarks:
Flatten Arrays - Large
new Array() vs Array.from()
Float32 vs Float64 vs Array
new Uint8Array() vs Uint8Array.from() reverse
Comments
Confirm delete:
Do you really want to delete benchmark?