startsWith+substring vs replace

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
startsWidth+substring
const data = ["-","Car","Motorcycle","Bicycle","Bus","Boat","Walk","Group::A::A","Group::AB::C::Leaf","Group::B::B","Group::A::Leaf","Group::B::C","Branch::Branch","Branch::Leaf"]

const oldLabel = "Branch::";
const newLabel = "Bug::";

          data.forEach((label) => {
            if (label.startsWith(oldLabel)) {
              const name = newLabel + label.substring(oldLabel);
            }
          });
ready
replace
const data = ["-","Car","Motorcycle","Bicycle","Bus","Boat","Walk","Group::A::A","Group::AB::C::Leaf","Group::B::B","Group::A::Leaf","Group::B::C","Branch::Branch","Branch::Leaf"]

const oldLabel = "Branch::";
const newLabel = "Bug::";

          data.forEach((label) => {
          	const x = label.replace(oldLabel, newLabel)
            if (name !== label) {
              const name = x;
            }
          });
ready

Revisions

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