counting with push

JavaScript performance comparison

Test case created by Kenan Yildirim

Info

Quick test with counting occurrences of something using an array instead of numbers.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function noop() {}
};
</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
count with an array
var caps = [];

var index = -1;
var length = 1000;
while (index++ < length) {
  caps.push(true);
}

noop(caps.length);
pending…
count with a number
var caps = 0;

var index = -1;
var length = 1000;
while (index++ < length) {
  caps++;
}

noop(caps);
pending…

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

Compare results of other browsers

0 comments

Add a comment