join-vs-for-vs-repeat (v5)

Revision 5 of this benchmark created by Khoa Nguyen on


Test runner

Ready to run.

Testing in
TestOps/sec
Join
var a = new Array(100000).join("a") + "bcd";
ready
for
var a = "bcd";
for (var i = 0; i < 100000; ++i) {
    a = "a" + a;
}
ready
for binary
var a = "";
for (var i = 100000, s = "a"; i != 0; i >>= 1) {
    if (i & 1) a += s;
    s += s;
}
ready
string repeat
var n = 100000;
var string = "a";

(" ".repeat(n) + string).slice(-n)
ready

Revisions

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

  • Revision 1: published by polkovnikov.ph on
  • Revision 5: published by Khoa Nguyen on