Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Zero-fill Uint8Array
(version: 2)
Comparing performance of:
Native fill vs Fill with loop vs New array
Created:
9 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var size = 1080 * 720; var globalArray = new Uint8Array(size);
Tests:
Native fill
globalArray.fill(0);
Fill with loop
var n = size; while(n--) globalArray[n] = 0;
New array
globalArray = new Uint8Array(size);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native fill
Fill with loop
New array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native fill
359841.7 Ops/sec
Fill with loop
1582.1 Ops/sec
New array
39201.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Overview** The benchmark measures the performance of filling a `Uint8Array` with zeros using three different approaches: native `fill()`, fill using a loop, and creating a new array. **Options Compared** 1. **Native `fill()`**: This method is part of the JavaScript standard library and directly fills the entire array with zeros. 2. **Fill with Loop**: This approach uses a while loop to iterate over each element in the array and sets it to zero individually. 3. **New Array**: This option creates a new, empty `Uint8Array` instance and assigns it to the global variable. **Pros and Cons** 1. **Native `fill()`**: * Pros: Fast and efficient, as it's a built-in method optimized for performance. * Cons: May have limitations or quirks depending on the browser implementation. 2. **Fill with Loop**: * Pros: Can be useful for understanding low-level array manipulation. * Cons: Slower than native `fill()` due to the overhead of the loop and individual assignments. 3. **New Array**: * Pros: May be useful for demonstrating array creation and reuse. * Cons: Creates a new, unnecessary object, which can lead to increased memory allocation and garbage collection. **Library/Extension** In this benchmark, no external libraries are used. However, the `Uint8Array` class is a built-in JavaScript class that represents an array of unsigned 8-bit integers. **Special JS Feature/Syntax** There are no special JavaScript features or syntax mentioned in this benchmark. It's purely focused on measuring performance. **Other Alternatives** If you wanted to test alternative approaches, you could consider: * Using `Buffer.fill()` (for Node.js) or `TypedArray.prototype.fill()` (for modern browsers) * Implementing a custom loop-based fill function * Using WebAssembly (WASM) or other low-level optimization techniques In summary, this benchmark measures the performance of three different approaches to filling a `Uint8Array` with zeros: native `fill()`, fill using a loop, and creating a new array. The results provide insight into which approach is most efficient for this specific use case.
Related benchmarks:
Shifting array elements
Array vs UInt8Array resizing
JS number to UInt8Array 64-bit little endian
JS number to UInt8Array 64-bit little endian 2
Comments
Confirm delete:
Do you really want to delete benchmark?