array vs string

Benchmark created on


Setup

const args = ["test", { "a": "b"}, "c", "d", [1,2,3], {"e":"f"}]

Test runner

Ready to run.

Testing in
TestOps/sec
string
var output = "";
for (var i = 0, len = args.length; i<len; i++){
  if (typeof args[i] === "object") {
    output = `${output},${JSON.stringify(args[i])}`;
  } else {
    output = `${output},${args[i]}`;
  }
}
output = output.slice(1)
ready
array
var output=[];
for(var i =0, len = args.length; i<len; i++) {
  if (typeof args[i] === "object") { 
    output.push(JSON.stringify(args[i]));
  } else {
    output.push(args[i]);
  }
}
output = output.join(",");
ready

Revisions

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