diff --git a/src/benchmarks.js b/src/benchmarks.js index 7f6d856..3689709 100644 --- a/src/benchmarks.js +++ b/src/benchmarks.js @@ -47,18 +47,30 @@ function buildMapSuite(array) { return array.map(({ a, b }) => a + b); }) .add("for of", function () { - const result = []; - for (const obj of array) { - result.push(obj.a + obj.b); + try { + const result = new Array(array.length) + let i = 0 + for (const obj of array) { + result[i] = obj.a + obj.b; + i++ + } + return result; + } catch (err) { + console.error(err) } - return result; }) .add("for of, destructuring", function () { - const result = []; - for (const { a, b } of array) { - result.push(a + b); + try { + const result = new Array(array.length) + let i = 0 + for (const { a, b } of array) { + result[i] = a + b + i++ + } + return result; + } catch (err) { + console.error(err) } - return result; }) .add("for, init array", function () { const result = new Array(array.length); diff --git a/src/index.js b/src/index.js index 39cfba8..693136c 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,6 @@ function generateTestArray() { const testArray = generateTestArray(); -runSuite(buildForEachSuite(testArray)); +//runSuite(buildForEachSuite(testArray)); runSuite(buildMapSuite(testArray)); -runSuite(buildReduceSuite(testArray)); +//runSuite(buildReduceSuite(testArray));