toString() vs if

Benchmark created on


Setup

const fileA = { version : "1.4" };

Test runner

Ready to run.

Testing in
TestOps/sec
toString
if(typeof fileA.version === "number" || typeof fileA.version === "string") {
    fileA.versionId = fileA.version.toString().split(".").map((num, idx) => num - (idx === 0 ? 1 : 0)).join(".");
}
ready
if
if(typeof fileA.version === "number") {
    fileA.versionId = fileA.version.toString().split(".").map((num, idx) => num - (idx === 0 ? 1 : 0)).join(".");
} else if(typeof fileA.version === "string") {
    fileA.versionId = fileA.version.split(".").map((num, idx) => num - (idx === 0 ? 1 : 0)).join(".");
}
ready

Revisions

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