Fastest way to empty a array

JavaScript performance comparison

Revision 8 of this test case created

Info

Empty a array, not change the reference of a variable to a new array.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [1,2,3,4,5,6,7,8,9,0];
};
</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
length equal to 0 method
a.length = 0;
pending…
while
while (a.length > 0) a.pop();
pending…
splice
a.splice(0, a.length);
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