array vs set add then join

JavaScript performance comparison

Test case created by LitenApe

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const args = ["arg1",{hello: true},"arg3",{hello: true},"arg4",{hello: true},"arg5",{hello: true},"arg6",{hello: true},"arg7",{hello: true},"arg8",{hello: true},"arg9",{hello: true},"arg10",{hello: true},"arg11",{hello: true},"arg12",{hello: true},"arg13",{hello: true},"arg14",{hello: true},"arg15",{hello: true},"arg16",{hello: true},"arg17",{hello: true},"arg18",{hello: true},"arg19",{hello: true},"arg20"];

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
concat-string
let resultString = "";

args.forEach(arg => resultString = `${resultString} ${arg}`)
pending…
set-based-operation
const setList = new Set();

args.forEach(arg => setList.add(arg));

new Array(setList).join(" ");
pending…
array-based-operation
const arrList = new Array();

args.forEach(arg => arrList.push(arg));

arrList.join(" ");
pending…

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

Compare results of other browsers

0 Comments