Fastest way to clear a typed array

Benchmark created by Joseph Gentle on


Description

Note that this result is NOT CONSISTENT if you use Uint32 arrays instead.

Setup

var SIZE = 100000;
    var array = new Uint8Array(SIZE);
    // Put some junk in it.
    for (var i = 0; i < SIZE; i++) array[i] = i % 100;

Test runner

Ready to run.

Testing in
TestOps/sec
Loop through and zero
for (var i = 0; i < SIZE; i++) array[i] = 0;
ready
Reallocate
array = new Uint8Array(SIZE);
 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Joseph Gentle on