Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
split vs splitstring
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.20 Safari/537.36
Browser:
Chrome 104
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
splitstring
737647.7 Ops/sec
split
4836616.5 Ops/sec
Tests:
splitstring
function splitString(str = "", splitter = "", includeSplitter = false) { function getlast(string, len) { if (len > string.length) return -1; let s = ""; let o = string.length - 1 - len; for (let i = string.length - 1; i > o; i--) { s = string[i] + s; } return s; } if (typeof str !== "string" || typeof splitter !== "string") return str; if (!str.length) return [str]; let strPieces = []; if (!splitter.length) { for (let p = 0; p < str.length; p++) { strPieces.push(str[p]); } return [...strPieces]; } let splitterLen = splitter.length; let strCurPiece = ""; let tempStr = ""; for (let v = 0; v < str.length; v++) { strCurPiece += str[v]; if (strCurPiece.length < splitterLen) continue; //let lastchars = strCurPiece.last(splitterLen); let lastchars = getlast(strCurPiece, splitterLen); if (lastchars !== splitter) continue; if (includeSplitter) { strPieces.push(strCurPiece); strCurPiece = ""; continue; } let lenny = strCurPiece.length - splitterLen; for (let y = 0; y < lenny; y++) { tempStr += strCurPiece[y]; } strPieces.push(tempStr); strCurPiece = ""; tempStr = ""; } if (strCurPiece.length) strPieces.push(strCurPiece); return [...strPieces]; } splitString('dfasfasfaqqq','qqq')
split
'dfasfasfaqqq'.split('qqq')