split test

Benchmark created on


Setup

const input = [
"Group::AB::C::Leaf",
"Group::AB::C",
"Group::AB",
"Group"
];

Test runner

Ready to run.

Testing in
TestOps/sec
BY SPLIT
input.forEach((name) => {
const parts = name.split('::')
})
ready
By while loop
const getSplitParts = (name) => {
    if (!name) return []; // Return empty array for undefined or empty input

  const delimiter = "::";
  const result = [];
  let currentPart = '';
  const delimiterLength = delimiter.length;

  for (let i = 0; i <= name.length; i++) {
    // Check for the end of the string or if we hit the delimiter
    if (i === name.length || name.substring(i, i + delimiterLength) === delimiter) {
      result.push(currentPart); // Add the current part to the result
      currentPart = ''; // Reset current part for the next substring
      i += delimiterLength - 1; // Skip past the delimiter
    } else {
      currentPart += name[i]; // Build the current part
    }
  }

  return result;


};
input.forEach((name) => {
const parts = getSplitParts(name)
})
ready

Revisions

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