Test name | Executions per second |
---|---|
forEach | 5235746.0 Ops/sec |
for | 13095759.0 Ops/sec |
for optimized | 13159533.0 Ops/sec |
reduce | 14091031.0 Ops/sec |
while | 9659842.0 Ops/sec |
for in | 471848.3 Ops/sec |
for of | 3779423.2 Ops/sec |
for of babel | 1799.6 Ops/sec |
<script>
Benchmark.prototype.setup = function() {
var testData = [];
for (var i = 0; i < 100; i++) {
testData.push(i);
}
};
</script>
var res = 0;
testData.forEach(function(x) {
res += x;
});
var res = 0;
for (var i = 0; i < testData.length; i++) {
res += testData[i];
}
var res = 0;
for (var i = 0, len = testData.length; i < len; i++) {
res += testData[i];
}
var res = testData.reduce(function(sum, x) {
return sum + x;
}, 0);
var res = 0;
var i = testData.length;
while (i--) {
res += testData[i];
}
var res = 0;
for (var data in testData) {
res += testData[i];
}
var res = 0;
for (var data of testData) {
res += testData[i];
}
var res = 0;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = testData[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var value = _step.value;
console.log(value);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
res += testData[i];
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}