mapFilter
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
native |
|
pending… |
facade |
|
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:
- Revision 1: published by ryanve
- Revision 2: published by ryanve
0 comments