Filtering defined values in array
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var i, len = 1000;
var array = new Array(len);
for (i = 0; i < len; i += 3) {
array[i] = 1;
}
function filterFn(item) {
return typeof item !== 'undefined';
}
var result;
var typedArray = new Uint8Array(array);
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Array.filter |
|
pending… |
for loop |
|
pending… |
for in |
|
pending… |
for loop typed |
|
pending… |
for in typed |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments