mapFilter

JavaScript performance comparison

Test case created by ryanve

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [0, 1, 2, 3, true, false, null];
  
  /**
   * Map an array (or array-like object) and then compact the result. 
   * Both operations are combined into one loop.
   * @param  {Object|Array|*}  list
   * @param  {function(...)}   fn
   * @return {Array}
   */
  function mapFilter(list, fn, scope) {
  	var l, i = 0, v, ret = [];
  	if (list == null) { return ret; }
  	for (l = list.length; i < l; i++) {
  		i in list && (v = fn.call(scope, list[i], i, list)) && ret.push(v);
  	}
  	return ret;
  }

};
</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
native
arr.map(isFinite).filter(function(n){return !!n;});
pending…
facade
mapFilter(arr, isFinite);
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.

0 Comments