Multi filter vs combined

JavaScript performance comparison

Test case created by wygoodin

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const numbers = new Array(256);
  for (let i = 0; i < 256; ++i) {
      numbers[i] = i;
  }
  const manyNumbers = new Array(2048);
  for (let i = 0; i < 2048; ++i) {
      numbers[i] = i;
  }
  

};
</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
Combined with push large
const result1 = [];
const result2 = [];
for (let i = 0; i < manyNumbers.length; ++i) {
    if (manyNumbers[i] > 1024) {
        result1.push(manyNumbers[i]);
    } else if (manyNumbers[i] < 1024) {
        result2.push(manyNumbers[i]);
    }
}
pending…
Two filters large
const result1 = manyNumbers.filter(x => x > 1024);
const result2 = manyNumbers.filter(x => x < 1024);
pending…
Two filters
const result1 = numbers.filter(x => x > 128);
const result2 = numbers.filter(x => x < 128);
pending…
Combined with push
const result1 = [];
const result2 = [];
for (let i = 0; i < numbers.length; ++i) {
    if (numbers[i] > 128) {
        result1.push(numbers[i]);
    } else if (numbers[i] < 128) {
        result2.push(numbers[i]);
    }
}
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