String concatenation

Benchmark created on


Setup

const BASE_URL = "https://example.com"
const PATH = "/example"
const QUERY_1 = "foo=bar"
const QUERY_2 = "baz=quux"
const FRAGMENT = "example"

Test runner

Ready to run.

Testing in
TestOps/sec
Template literal
console.log(
  `${BASE_URL}${PATH}?${QUERY_1}&${QUERY_2}#${FRAGMENT}`,
);
ready
String.prototype.concat (one call)
console.log(
  BASE_URL.concat(
    PATH,
    "?",
    QUERY_1,
    "&",
    QUERY_2,
    "#",
    FRAGMENT,
  ),
);
ready
String.prototype.concat (call on empty string)
console.log(
  "".concat(
    BASE_URL,
    PATH,
    "?",
    QUERY_1,
    "&",
    QUERY_2,
    "#",
    FRAGMENT,
  ),
);
ready
String.prototype.concat (chained)
console.log(
  BASE_URL.concat(PATH)
    .concat("?")
    .concat(QUERY_1)
    .concat("&")
    .concat(QUERY_2)
    .concat("#")
    .concat(FRAGMENT),
);
ready
Concatenation
console.log(
  BASE_URL +
    PATH +
    "?" +
    QUERY_1 +
    "&" +
    QUERY_2 +
    "#" +
    FRAGMENT,
);
ready

Revisions

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