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();
}
for (let i; i < size; i++) {
target[i] = source[i];
}
target.set(source);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Uint8Array by byte | |
Uint8Array with set |
Test name | Executions per second |
---|---|
Uint8Array by byte | 194567104.0 Ops/sec |
Uint8Array with set | 439326.7 Ops/sec |
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:
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.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:
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
set()
method (Uint8Array with set):set()
method.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:
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.Overall, this benchmark provides a simple yet informative comparison of two common approaches for copying data from one Uint8Array
to another in JavaScript.