Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
copy ArrayBuffer: Uint8Array.set vs by bytes
(version: 0)
Comparing performance of:
Uint8Array by byte vs Uint8Array with set
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var size = 0xFFFF; var source = new Uint8Array(size); var target = new Uint8Array(size); for (let i = 0; i < size; i++) { source[i] = 100*Math.random(); }
Tests:
Uint8Array by byte
for (let i; i < size; i++) { target[i] = source[i]; }
Uint8Array with set
target.set(source);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Uint8Array by byte
Uint8Array with set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0
Browser/OS:
Chrome 137 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Uint8Array by byte
96664152.0 Ops/sec
Uint8Array with set
1018247.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON benchmark and explain what's being tested, compared options, pros and cons, and other considerations. **Benchmark Definition** The benchmark is testing two different approaches to copy data from one `Uint8Array` to another: 1. `Uint8Array by byte`: This approach uses a traditional loop to iterate over each element of the source array and assign it to the corresponding index in the target array. 2. `Uint8Array with set`: This approach uses the `set()` method to copy the data from the source array to the target array. **Options Compared** The two options being compared are: * **Manual loop**: The traditional loop-based approach using a for loop to iterate over each element of the source array. * **Built-in `set()` method**: Using the `set()` method, which is a built-in method in JavaScript arrays, to copy data from one array to another. **Pros and Cons** * **Manual loop (Uint8Array by byte)**: + Pros: This approach provides direct control over the copying process, allowing for optimizations such as caching or specialized implementations. + Cons: This approach can be slower due to the overhead of explicit looping and indexing. * **Built-in `set()` method (Uint8Array with set)**: + Pros: This approach is generally faster since it leverages the optimized implementation of the `set()` method. + Cons: This approach has less control over the copying process, which might limit optimization opportunities. **Library/External Dependencies** There are no external libraries or dependencies mentioned in the provided JSON benchmark. **Special JS Feature/Syntax** There are no special JavaScript features or syntax used in this benchmark. It's a straightforward comparison of two simple approaches. **Other Alternatives** Other alternatives to these two options might include: * Using `Array.prototype.slice()` and assignment: This approach would create a new array with the desired range of elements from the source array and assign it to the target array. * Using a specialized library like WebAssembly or SIMD instructions (if supported by JavaScript engines): These approaches could potentially provide even faster copying times, but might also add complexity and dependencies. Overall, this benchmark provides a simple yet informative comparison of two common approaches for copying data from one `Uint8Array` to another in JavaScript.
Related benchmarks:
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes vs function
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes (2)
Uint32Array copy vs set
Comments
Confirm delete:
Do you really want to delete benchmark?