Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
new Uint8Array() vs Uint8Array.from()
(version: 0)
Test ArrayBuffer creation methods on a random Array
Comparing performance of:
Test new Uint8Array() vs Test Uint8Array.from()
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var randomArray = Array.from({ length: 1000 }, () => Math.floor(Math.random() * 256))
Tests:
Test new Uint8Array()
new Uint8Array(randomArray)
Test Uint8Array.from()
Uint8Array.from(randomArray)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Test new Uint8Array()
Test Uint8Array.from()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Test new Uint8Array()
223958.2 Ops/sec
Test Uint8Array.from()
306151.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **What is being tested?** The benchmark measures the performance difference between creating a `Uint8Array` using two different methods: 1. **`new Uint8Array()`**: This method creates a new `Uint8Array` object from an empty array. 2. **`Uint8Array.from()`**: This method creates a new `Uint8Array` object from an existing array. **Options compared** The benchmark compares the performance of these two methods on a randomly generated array of 1000 elements, where each element is a random integer between 0 and 255 (inclusive). The goal is to determine which method is faster for creating large arrays. **Pros and Cons of each approach:** * **`new Uint8Array()`**: This method creates an empty `Uint8Array` object and then populates it with the elements from the random array. This approach can be beneficial if you need to create a `Uint8Array` object without any pre-existing data, but it may incur additional overhead due to the repeated allocation of memory. * **`Uint8Array.from()`**: This method creates a new `Uint8Array` object and populates it with the elements from the random array in a single operation. This approach is generally faster because it avoids the need for repeated allocation of memory. **Library used** In this benchmark, the `Uint8Array` class is not specifically tied to any library or framework. It is a built-in JavaScript class that is part of the ECMAScript standard. **Special JS feature or syntax** There are no specific special features or syntax mentioned in the benchmark. However, it's worth noting that the use of `new Uint8Array()` and `Uint8Array.from()` relies on JavaScript's array creation methods, which are supported by most modern browsers. **Other alternatives** If you need to create a large array quickly, there are other approaches you could consider: * Using the `Array.prototype.fill()` method: This method can be used to populate an existing array with values, but it requires that the array is already populated. * Using the `Array.prototype.set()` method: This method can be used to set the values of a large array in place, but it also requires that the array is already populated. * Using native WebAssembly arrays (if supported by your browser): WebAssembly arrays provide a low-level interface for creating and manipulating arrays, which may offer better performance than JavaScript's built-in `Uint8Array` class. Keep in mind that these alternatives may have different trade-offs and use cases compared to the original benchmark.
Related benchmarks:
repeated Math.random() vs crypto.getRandomValues()
new Array() vs Array.from()
new Array() vs Array.from() with random data
new Uint8Array() vs Uint8Array.from() reverse
Comments
Confirm delete:
Do you really want to delete benchmark?