for vs fiter.map

JavaScript performance comparison

Test case created by sml86

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [
                  {s: 'a', n: 12, b: true},
                  {s: 'b', n: 15, b: false},
                  {s: 'c', n: 234, b: true},
                  {s: 'd', n: 876, b: false},
                  {s: 'e', n: 83, b: true},
                  {s: 'f', n: 123, b: false},
                  {s: 'g', n: 453, b: true},
                  {s: 'h', n: 13, b: false},
                  {s: 'i', n: 954, b: true},
                  {s: 'j', n: 34, b: false},
                  {s: 'k', n: 65, b: true},
                  {s: 'l', n: 45, b: false}
              ];
  
  function f (o) {
    return o;
  }

};
</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
filter.map
var an = a.filter(o => o.b).map(o => f(o));
pending…
for loop
var an = [], i = 0; 
for ( ; i < a.length; ++i) { 
  if (a[i].b) {
    an.push(f(a[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