JS Perf for of vs concat (v2)

Revision 2 of this benchmark created on


Description

Test if For Of loop for each element appending is appreciably slower than concatting

Test runner

Ready to run.

Testing in
TestOps/sec
For Of Push
const input = [
  "ab", "xyz", "hello", "javascript", "programming", "webdevelopment", "functionality",
  "aVeryLongStringThatIsMuchLongerThanTheOthersToShowVariabilityInLength", "short", "medium",
  "anotherVeryLongStringThatShowsHowTheVariableLengthWorksInThisArrayOfStringsWeAreCreating",
  "js", "css", "html", "react", "node", "express", "mongodb", "postgresql", "typescript",
  "aBitLongerStringToAddMoreVariability", "redux", "context", "hooks", "components", "props",
  "ThisStringIsLongerThanManyOthersButNotAsLongAsTheLongestOneInTheArray", "routing", "api",
  "axios", "fetch", "promises", "async", "await", "functions", "objects", "arrays", "methods",
  "aReallyReallyLongStringThatTakesUpLotsOfSpaceAndIsCloseToTheMaximumLengthWeSpecifiedForTheVariableLengthStrings",
  "prototypes", "closures", "scopes", "hoisting", "callstack", "eventloop", "callback", "higher",
  "AnotherVeryLongStringToAddMoreVarietyToTheLengthsOfTheStringsInThisConstantArray", "map",
  "filter", "reduce", "find", "some", "every", "includes", "indexOf", "lastIndexOf", "concat",
  "slice", "splice", "pop", "push", "shift", "unshift", "reverse", "sort", "join", "split",
  "ThisIsYetAnotherLongStringThatAddsToTheVariabilityOfTheLengthsInTheArrayWeAreCreating",
  "trim", "padStart", "padEnd", "replace", "match", "search", "startsWith", "endsWith", "keys",
  "values", "entries", "forEach", "Object", "Array", "String", "Number", "Boolean", "RegExp",
  "ThisIsTheLastReallyLongStringInTheArrayAndItIsAlsoOneOfTheLongestToMaximizeTheVariability",
  "Math", "Date", "JSON", "Error", "Promise", "Proxy", "Set", "Map", "Symbol", "cd"
];
let output = []
for (const element of input.pop()) {
	output.push(element)
}
ready
Concat
const input = [
  "ab", "xyz", "hello", "javascript", "programming", "webdevelopment", "functionality",
  "aVeryLongStringThatIsMuchLongerThanTheOthersToShowVariabilityInLength", "short", "medium",
  "anotherVeryLongStringThatShowsHowTheVariableLengthWorksInThisArrayOfStringsWeAreCreating",
  "js", "css", "html", "react", "node", "express", "mongodb", "postgresql", "typescript",
  "aBitLongerStringToAddMoreVariability", "redux", "context", "hooks", "components", "props",
  "ThisStringIsLongerThanManyOthersButNotAsLongAsTheLongestOneInTheArray", "routing", "api",
  "axios", "fetch", "promises", "async", "await", "functions", "objects", "arrays", "methods",
  "aReallyReallyLongStringThatTakesUpLotsOfSpaceAndIsCloseToTheMaximumLengthWeSpecifiedForTheVariableLengthStrings",
  "prototypes", "closures", "scopes", "hoisting", "callstack", "eventloop", "callback", "higher",
  "AnotherVeryLongStringToAddMoreVarietyToTheLengthsOfTheStringsInThisConstantArray", "map",
  "filter", "reduce", "find", "some", "every", "includes", "indexOf", "lastIndexOf", "concat",
  "slice", "splice", "pop", "push", "shift", "unshift", "reverse", "sort", "join", "split",
  "ThisIsYetAnotherLongStringThatAddsToTheVariabilityOfTheLengthsInTheArrayWeAreCreating",
  "trim", "padStart", "padEnd", "replace", "match", "search", "startsWith", "endsWith", "keys",
  "values", "entries", "forEach", "Object", "Array", "String", "Number", "Boolean", "RegExp",
  "ThisIsTheLastReallyLongStringInTheArrayAndItIsAlsoOneOfTheLongestToMaximizeTheVariability",
  "Math", "Date", "JSON", "Error", "Promise", "Proxy", "Set", "Map", "Symbol", "cd"
];
let output = []
output.concat(input.pop())
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.