loop-test-123
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var arr1, funcA, funcB, execute;
arr1 = [];
for (x = 0; x < 50; x += 1) {
arr1.push(x.toString());
}
funcA = function(array, item) {
for (var i = 0, len = array.length; i < len; i++)
if (array[i] === item) return i;
return -1;
};
funcB = function(array, item) {
var t = Object(array);
var len = t.length >>> 0;
for (var i = 0; i < len; i++)
if (i in t && t[i] === item) return i;
return -1
};
execute = function(fn) {
fn(arr1, '0');
fn(arr1, '49');
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
funcA |
|
pending… |
funcB |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments