Array.slice() vs TypedArray.subarray()

Benchmark created by Heather on


Description

If you're doing a lot of slicing vs accesses, is it worth it to use a TypedArray instead of a regular Array?

Setup

var length = 1000;
    var start = 200;
    var end = 300;
    
    
    var array = new Array(length);
    for (var i = 0; i < array.length; i++) {
      array[i] = 0;
    }
    
    var typed64 = new Float64Array(length);
    var typed32 = new Float32Array(length);

Test runner

Ready to run.

Testing in
TestOps/sec
Array.slice()
array.slice(start, end);
ready
Float64Array.subarray()
typed64.subarray(start,end);
ready
Float32Array.subarray()
typed32.subarray(start,end);
ready

Revisions

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

  • Revision 1: published by Heather on
  • Revision 2: published by Moncader on
  • Revision 4: published by kevin on