array_clear

JavaScript performance comparison

Revision 3 of this test case created by uhas

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arr = [];
    for (var i = 0; i < 10000; i = i + 2)
      arr[i] = 'test';
};

Benchmark.prototype.teardown = function() {
    console.log(arr);
};
</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
pop
while (arr.length)
  arr.pop();
pending…
length
arr.length = 0;
pending…
splice
arr.splice(0, arr.length)
pending…
[]
arr = [];
pending…
pop (arr.length > 0)
while (arr.length > 0)
  arr.pop();
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