Array.slice() vs TypedArray.subarray()

JavaScript performance comparison

Test case created by Heather

Info

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

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    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);
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Array.slice()
array.slice(start, end);
pending…
Float64Array.subarray()
typed64.subarray(start,end);
pending…
Float32Array.subarray()
typed32.subarray(start,end);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment