new array vs splice vs slice

JavaScript performance comparison

Revision 2 of this test case created by Bruno Garcia

Preparation code

<script>
  var a;
</script>
    

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Slice
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
a = a.slice(10);
pending…
New
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
a = [];
pending…
Splice
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
a.splice(0, 10);
pending…
Zero length
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
a.length = 0;
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.

0 Comments