Test name | Executions per second |
---|---|
forEach | 7116.5 Ops/sec |
for..of | 7447.7 Ops/sec |
var arr_num = [];
for (var i = 0; i < 1000; i++) {
arr_num.push(i);
}
function numFn(i) {
i = i * 3 * 8;
}
var arr_str = [];
for (var i = 0; i < 1000; i++) {
arr_str.push((Math.random() + 1).toString(36).substring(7));
}
function strFn(i) {
i = i + '_';
}
var arr_obj = [];
for (var i = 0; i < 1000; i++) {
arr_obj.push({
[(Math.random() + 1).toString(36).substring(7)]: true
});
}
function objFn(i) {
i.aaa = false;
}
arr_num.forEach((item) => {
numFn(item);
});
arr_str.forEach((item) => {
strFn(item);
});
arr_obj.forEach((item) => {
objFn(item);
});
for (const element of arr_num) {
numFn(element);
}
for (const element of arr_str) {
strFn(element);
}
for (const element of arr_obj) {
objFn(element);
}